I'm trying to implement a Dropdownlist that displays data from database. The code for my implementation is as follows:
View
<div class="form-group">
@Html.Label("Select Your User Type", new { @class = "col-md-2 control-label" })
<div class="col-md-10">
@Html.DropDownList("Drop")
</div>
</div>
Controller
ViewBag.Drop = new SelectList(db.Roles, "Name", "Name");
I have checked that many online tutorials uses this method. However, whenever I try to save the information, it gives off the error as follows:
I checked the datatype for the ViewBag.Drop and it was System.Web.Mvc.SelectListItem
datatype instead of the IEnumerable<SelectListItem
needed for the Html.DropDownlist
helper function.
What should I do and how come it changes the type to System.Web.Mvc.SelectListItem
???