views:

126

answers:

1

Hi, 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

+10  A: 
<%= Html.DropDownList("NumberSelection",
                      Enumerable.Range(0, 11)
                           .Select(x => new SelectListItem
                                            {
                                                 Text=x.ToString(),
                                                 Value=x.ToString()
                                            }
                                  )) %>
schinazi