Rich

Rich

  • NA
  • 84
  • 61.2k

MVC SelectList error

May 14 2012 6:36 PM
I have a SelectList that I have passed into a form in my view.  When I try to post it I get this error:

There is no ViewData item of type 'IEnumerable<SelectListItem>' that has the key 'roleName'.

Code in Controller:
ViewBag.roleName = new SelectList(Roles.GetAllRoles().Where(rn =>
                rn != "Administrator" && rn != "Special"));
Code in View:
@Html.DropDownList("roleName", ViewBag.roleName as SelectList, "Select")

Answers (3)