我如何实现此网格的Ajax?
@{
var grid = new WebGrid(source: Model, defaultSort: "FirstName", rowsPerPage: 5);
}
@if (Model.Count() > 0)
{
<div id="grid">
@grid.GetHtml(
tableStyle: "grid",
headerStyle: "head",
alternatingRowStyle: "alt",
columns: grid.Columns(
grid.Column("FirstName", "First Name"),
grid.Column("LastName", "Last Name"),
grid.Column("Address"),
grid.Column("DOB"),
grid.Column("Gender")
)
)
</div>
}
我尝试添加ajaxUpdateContainerId,但它给出了一些错误。 我无法理解。
我创建了我的网格,如下所示
var grid = new WebGrid(canPage: true, rowsPerPage: 2, defaultSort: "FirstName", canSort: true, ajaxUpdateContainerId: "grid");
grid.Bind(Model, rowCount:Model.Count(), autoSortAndPage: false);
grid.Pager(WebGridPagerModes.All);
但它显示了网格中的所有记录,我想在网格中只显示5条记录然后分页
答案 0 :(得分:1)
这里有一篇很棒的文章http://www.unboxedsolutions.com/sean/archive/2011/01/23/15964.aspx
@using AdventureWorks.Common
@using ThisController = MvcDemo.Controllers.GridExampleController
@model GridExampleViewModel
@{ ViewBag.Title = "Index"; }
@{
var grid = new WebGrid(canPage: true, rowsPerPage: ThisController.PageSize, canSort: true, ajaxUpdateContainerId: "grid");
grid.Bind(Model.Employees, rowCount: Model.TotalRecords, autoSortAndPage: false);
grid.Pager(WebGridPagerModes.All);
@grid.GetHtml(htmlAttributes: new { id="grid" },
columns: grid.Columns(
grid.Column(format: (item) => Html.ActionLink("Edit", "Edit", new { EmployeeID = item.EmployeeID, ContactID = item.ContactID })),
grid.Column("FullName"),
grid.Column("Title")
));
}