I want to retrieve data from db into a model and pass it to the view
e.g.
1) db State table, has 2 columns Code and Text.
2) my model:
public class state
{
public IEnumerable<SelectListItem> list { get; set; }
public string selected { get; set; }
}
3) and I want the controller to place code and text data from state table into list and set selected to 1 and return the model to the view
how would I write the loop in the controller
Ideally, you could create a data access class to do what that above constructor does, but you should get the general idea of the code.
As for the Action method:
A corresponding View: