Just wondering if anyone can help with this problem. I have a viewmodel which populates a dropdownlist. I was just wondering if it's possible to change my code below so that I can use a for loop to populate the list.
ViewModel
public IEnumerable<SelectListItem> numberOfAdults { get; set; }
Controller
numberOfAdults = new[]
{
new SelectListItem {Value = "1", Text = "1"},
new SelectListItem {Value = "2", Text = "2"},
new SelectListItem {Value = "3", Text = "3"},
new SelectListItem {Value = "4", Text = "4"},
new SelectListItem {Value = "5", Text = "5"},
new SelectListItem {Value = "6", Text = "6"},
new SelectListItem {Value = "7", Text = "7"},
new SelectListItem {Value = "8", Text = "8"},
new SelectListItem {Value = "9", Text = "9"},
new SelectListItem {Value = "10", Text = "10"}
}
View
@Html.DropDownListFor(x => x.selectedAdultValue, new SelectList(Model.numberOfAdults, "Value", "Text"), null, new {@id="NumerOfAdults" })
Something like the following is what I would like, but not sure where to put it in model or controller.
for(int i = 0; i < 10; i++)
{
i;
}