Also check your controller to ensure you are not passing Roles.ToList() to the CreateRole view.
You can do this:
[HttpGet]
public ActionResult CreateRole()
{
var roles = from ur in db.roles
orderby ur.RoleName
select ur;
ViewBag.Listroles = roles.ToList();
return View();
}
where db is your DbContext.
And your view should look like this:
@{
if(ViewBag.Listroles != null){
foreach (var roles in ViewBag.Listroles)
{
<tr>
<td>@roles.RoleName</td>
<td>
@Html.ActionLink("Edit", "EditRoles", new { id=roles.RoleId }) |
@Html.ActionLink("Details", "Details", new { id=roles.RoleId }) |
@Html.ActionLink("Delete", "Delete", new { id=roles.RoleId })
</td>
</tr>
}
}
}
Let me know if my answer helps.
RoleIdfrom being displayed in my view while I'm using ` @Html.EditorForModel()` ?