【发布时间】:2011-07-24 03:04:54
【问题描述】:
我正在学习 MVC 3、Razor 和 EF Model First。
我正在处理一个项目,我在与主 Web 项目不同的项目中定义了 EF 模型。我正在尝试在视图中使用该模型访问数据。
我收到此错误:
我将 System.Data.Entity 添加到我的引用中。
控制器:
public ActionResult ListRole()
{
AuthDbContainer db = new AuthDbContainer();
List<Role> roles = db.Roles.ToList();
return View(roles);
}
查看:
@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>
感谢您的帮助。
更新
发生此错误是因为我的 web.config 中的程序集引用丢失。它已添加到我在项目中的引用中,但未添加到 web.config 中。 IIS 几乎在我的错误消息中告诉我这一点。我应该读得更好。很抱歉浪费了任何人的时间。我在 web.config 中添加了以下内容,现在效果很好:
<add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
【问题讨论】:
标签: c# asp.net entity-framework asp.net-mvc-3 razor