I am new on ASP.net MVC 3.0, I want to display my data to WebGrid and I write this code in the View.
@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>
Here are the controller
private MovieEntities db = new MovieEntities();
//
// GET: /Coba/
public ViewResult Index()
{
return View(db.MOVIEs.ToList());
}
After that I always get error "The result of a query cannot be enumerated more than once." What can I do to solve it?