Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Simplest method to create an asp.net mvc dropdownlist with values from 0 to 10?

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

like image 827
Kristof Avatar asked Dec 02 '22 06:12

Kristof


1 Answers

<%= Html.DropDownList("NumberSelection",
                      Enumerable.Range(0, 11)
                           .Select(x => new SelectListItem
                                            {
                                                 Text=x.ToString(),
                                                 Value=x.ToString()
                                            }
                                  )) %>
like image 164
schinazi Avatar answered May 16 '23 08:05

schinazi