I have this code:
columns.ForeignKey(p => p.SomeProperty, new SelectList(new[] { "0", "1", "2", "3", "4", "5" }));
And I want to populate the SelectList dinamically, not always from 0 to 5. Let’s say I have the upper limit saved in a Session["upperLimit"] variable. How to create a for loop in the view, so that the SelectList will go from 0 to Session["upperLimit"]?
I would create the select list in the Controller and pass it to the view instead.
View is for iterating the model. The business logic should be in controller.
However if you still want to do this in view you can do something like the following: