I'm in the process of learning MVC 3, Razor, and EF Model First.
I have a project I'm working on where I have defined the EF Model in a separate project from the main web project. I'm trying to access data using that model in a view.
I get this error:
I added the System.Data.Entity to my references.
Controller:
public ActionResult ListRole()
{
AuthDbContainer db = new AuthDbContainer();
List<Role> roles = db.Roles.ToList();
return View(roles);
}
View:
@model IEnumerable<WebSecurity.Role>
@{
ViewBag.Title = "Role List";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<!DOCTYPE html>
<html>
<head>
<title>ListRole</title>
</head>
<body>
<p>
@Html.ActionLink("Create New", "Create")
</p>
<table>
<tr>
<th>
desc
</th>
<th>
createDate
</th>
<th>
</th>
</tr>
@foreach (var item in Model)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.desc)
</td>
<td>
@Html.DisplayFor(modelItem => item.createDate)
</td>
<td>
@Html.ActionLink("Edit", "Edit", new { id = item.roleName }) |
@Html.ActionLink("Details", "Details", new { id = item.roleName }) |
@Html.ActionLink("Delete", "Delete", new { id = item.roleName })
</td>
</tr>
}
</table>
</body>
</html>
Thank you for any help.
UPDATE
This error happened because the assembly reference in my web.config was missing. It was added to my references in the project but not in the web.config. IIS pretty much tells me that in my error message. I should have read it better. Sorry for wasting anyones time. I added the following to my web.config and it works great now:
<add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />