In the controller i have :
public ActionResult Create()
{
ViewBag.dData = db.Bank.Select(b => b.Omschrijving).ToList();
return View();
}
and in the view:
@Html.DropDownList("Omschrijving",ViewBag.dData as List<SelectListItem>)
I get a error: There is no ViewData item of type 'IEnumerable<SelectListItem>' that has the key 'Omschrijving'
How can i fix it?
public ActionResult Create()
{
ViewBag.dData = db.Bank
.Select(b => new SelectListItem() { Key = b.Omschrijving }).ToList();
return View();
}
You'll also need to set the Value
property of the SelectListItem
.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments