I have an MVC3 drop down list that come from this code on the controller.
private SelectList progCodesList = new SelectList(new[] { "Description", "Requirements", "Development", "Testing", "Documentation" });
How can I fill the fields from a repository, to build the drop down dynamically?
Thanks.
Assuming you have the
progCodesin a database table, with progCode having the text, and progCodeId with a unique id, then you can read the table into a list ofSelectListItemas follows:You can then pass this
List<SelectListItem>to your view either in a strongly-typed model, or using the ViewBag.