I have problem in my code. I\'m using the registration form which comes with MVC5 , I added a field \"Role\" as a Dropdownlist to assign a role to the user while creating a
Make sure you add the list to the model before returning the view, or you will get this error. Example:
cshtml:
@model DelegatePortal.ViewModels.ImpersonateVendorViewModel
@using (Html.BeginForm("ImpersonateVendor", "Admin", FormMethod.Post))
{
@Html.DropDownListFor(model => model.Id, new SelectList(Model.Vendors, "Id", "Name"), "Choose a vendor", new { @class = "form-control form-control-sm " })
}
controller:
// GET: /Admin/ImpersonateVendor
public ActionResult ImpersonateVendor()
{
ImpersonateVendorViewModel model = new ImpersonateVendorViewModel();
var vendors = (from c in db.Vendors
select c).ToList();
model.Vendors = vendors; --> add list here
return View(model);
}