我是 ASP.net MVC 3.0 的新手,我想将我的数据显示到 WebGrid,并在视图中编写此代码。
@model IEnumerable<MvcApplication3.Models.MOVIE>
@{
ViewBag.Title = "Index";
}
<h2>Index</h2>
<p>
@Html.ActionLink("Create New", "Create")
@ViewBag.abc;
</p>
@Html.ActionLink("Asc Title", "Index", new { sortOrder = "asc" })
@Html.ActionLink("Desc Title", "Index", new { sortOrder = "desc" })
<table>
<tr>
<th>
TITLE
</th>
<th>
PRICE
</th>
<th>
RELEASEDATE
</th>
<th></th>
</tr>
@foreach (var item in Model) {
<tr>
<td>
@Html.DisplayFor(modelItem => item.TITLE)
</td>
<td align="right">
@Html.DisplayFor(modelItem => item.PRICE)
</td>
<td>
@Html.DisplayFor(modelItem => item.RELEASEDATE)
</td>
<td>
@Html.ActionLink("Edit Saya", "Edit", new { id=item.ID }) |
@Html.ActionLink("Details", "Details", new { id=item.ID }) |
@Html.ActionLink("Delete", "Delete", new { id=item.ID }) |
@Html.ActionLink("Select", "MoviedanArtis", new { id = item.ID })
</td>
</tr>
}
</table>
@{
var grid = new WebGrid(Model.ToList(), rowsPerPage: 6);
}
<div id="grid">
@grid.GetHtml(tableStyle: "grid",
headerStyle: "head",
alternatingRowStyle: "alt",
columns: grid.Columns(grid.Column("TITLE"), grid.Column("PRICE"), grid.Column("RELEASEDATE")))
</div>
这是控制器
private MovieEntities db = new MovieEntities();
//
// GET: /Coba/
public ViewResult Index()
{
return View(db.MOVIEs.ToList());
}
之后我总是得到错误“查询的结果不能被枚举多次”。我能做些什么来解决它?