Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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() })
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading