顯示具有 DropDownList 標籤的文章。 顯示所有文章
顯示具有 DropDownList 標籤的文章。 顯示所有文章

2016年12月4日 星期日

[MVC][Razor][C#] How to populate dropdown list with numbers


A note to myself


@Html.DropDownListFor(m=>m.Name, Enumerable.Range(1, 10).Select(i => new SelectListItem { Text = i.ToString(), Value = i.ToString() }))



@Html.DropDownListFor(m => m.NumberOfTickets, Enumerable.Range(1, 10).Select(i => new SelectListItem { Text = i.ToString(), Value = i.ToString() }))



Ref:
1. How to populate dropdown list with numbers
http://stackoverflow.com/questions/29659911/asp-net-mvc-how-to-populate-dropdown-list-with-numbers
2. SelectList for years
http://stackoverflow.com/questions/13959098/selectlist-for-years