This is probably very simple ... I'm trying to create a SelectList containing years from the current, until 2008. It will always be so. For example, in 2020, my SelectList will contain values ββfrom 2020 to 2008.
I set up this loop, but I'm not sure what is the best thing to do for this.
for (int i = currentYear; i != 2009; --i) { }
Is it possible to create one SelectListItem and "add" it to the SelectList for each iteration?
I donβt think my expression above is possible, so my next thought was to create a list of years and then use LINQ to create it.
var selectList = ListOfYears.Select(new SelectListItem { Value = Text = });
But then I'm not quite sure how to get the value from the list. Thanks
Jeff
source share