asp mvc razor fill Html.DropDownList

user2257651

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?

Kehlan Krumme
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.

edited at
0

Comments

0 comments
Login to comment

Related