I'm new to asp.net mvc, so excuse me if my question is too simple.
I just want a dropdownlist that goes from 0 to 10 using Html.DropDownList. What is the fastest way? At the moment i only see the solution creating a IEnumerable of SelectListItem, add 10 values and pass it through with the viewdata, but i think that's overkill, how to do it in a simple way ?
Thanks in advance
<%= Html.DropDownList("NumberSelection",
Enumerable.Range(0, 11)
.Select(x => new SelectListItem
{
Text=x.ToString(),
Value=x.ToString()
}
)) %>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With