I'm trying to populate a @Html.DropDownList with a List using MVC and Razor. Bellow is my code for the controller. So I need to pick the list out of my ViewBag and fill the dropdownlist.
public ActionResult Register()
{
sparklingEntities context = new sparklingEntities();
var query = (from discs in context.Disciplines
select discs).ToList();
List<string> listOfDiscs = new List<string>();
foreach (var item in query)
{
listOfDiscs.Add(item.Discipline);
}
ViewBag.ListOfDisciplines = listOfDiscs;
return View();
}
Thanks for the help.