I have seen similar examples where people need to populate with a list of object but all I would like to achieve is to have the numbers 10,20,30...100 in my DropdownlistFor
in my view.
I use
@Html.DropDownListFor(
m => m.NumberOfTickets,
Enumerable.Range(1, 10)
.Select(i => new SelectListItem
{
Text = i.ToString(),
Value = i.ToString()
}))
CodePudding user response:
Use following code to get steps of 10s:
Enumerable
.Range(1, 10)
.Select(i => i * 10) // <- here is the clue others already suggested
.Select(i => new SelectListItem { Text = i.ToString(), Value = i.ToString() })