I am trying to list the users in a dropdownlist, this is my controller:
var user = db.Users.Where(e => e.Roles.All(r => r.RoleId != "1"))
.OrderBy(e => e.UserName);
ViewBag.UserId = new SelectList(user,"Id", "UserName");
return View();
This is my View:
@Html.DropDownList("UserId", null, htmlAttributes: new { @class = "form-control" })
I can display the users on the dropdownlist but when I try to post something, ModelState is not being valid and it gives that error.