Search code examples
asp.netasp.net-mvcmodel-view-controllerdropdown

Asp .Net MVC Dropdown


I want to display range from 2000 to 2020, so I am using this:

 @Html.DropDownListFor(p => p.Year, Enumerable.Range(2000, 2020)
    .Select(x => new SelectListItem { Text = x.ToString(),
    Value = x.ToString() }));

But it is displaying Range from 2000 to 4019.


Solution

  • You need to pass count as second parameter here.

    Learn more about Enumerable.Range

    Enumerable.Range(2000, 21)