我试图在MVC 5中找到一个关于webgrid的好例子,其中包括自定义分页排序和使用多个文本框进行搜索。
我们可以使用web网格和分页来引导它们吗?
@{
WebGrid grid = new WebGrid(rowsPerPage: Model.PageSize, defaultSort: "Name", ajaxUpdateContainerId: "grid");
grid.Bind(Model.Customer, autoSortAndPage: false, rowCount: Model.TotalRows);
@grid.GetHtml(htmlAttributes: new { id = "grid" }, // id for ajaxUpdateContainerId parameter
fillEmptyRows: false,
tableStyle: "table table-striped table-hover",
alternatingRowStyle: "alternate-row",
headerStyle: "grid-header",
footerStyle: "table-responsive",
numericLinksCount: 15,
columns: new[] {
grid.Column("CustID",header: "ID", canSort: false, style:"width:10%"),
grid.Column("Name",header: string.Format("Name {0}", grid.SortColumn == "Name" ? grid.SortDirection == SortDirection.Ascending ? "⇈" : "⇊" : ""), style:"width:20%", format: @<text>@item.GetSelectLink(item.Name)</text>),
grid.Column("Address",style:"width:400px"),
grid.Column("ContactNo",header: "Contact No", style:"width:20%")
}
)
<div class="row">
<div class="pull-right">
(@Model.ResultCount)
</div>
<div class="pull-left">
@grid.PagerList(mode: WebGridPagerModes.All,
paginationStyle: "pagination pagination-sm"
)
</div>
</div>
}
在此示例中,我使用了pagerList,autoSortPage为false,但它仍然显示webgrid分页以及自定义分页器。