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

沒有留言:

張貼留言