Home > Blockchain >  ASP.NET Core MVC how to populate dropdown list with numbers 10,20,30,40,50...100. I generate 1,2,3
ASP.NET Core MVC how to populate dropdown list with numbers 10,20,30,40,50...100. I generate 1,2,3

Time:11-16

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() })
  • Related