这是我认为的代码。WebGrid 排序和过滤器工作正常。我正在尝试实现没有发生的分页。
看法:
@{
var grid = new WebGrid(null,
defaultSort: "",
rowsPerPage: 10,
selectionFieldName:"SearchString",
ajaxUpdateContainerId:"agrid",
sortFieldName:"SortColumn",
sortDirectionFieldName:"SortOrder");
grid.Bind(Model, autoSortAndPage: true, rowCount:20);
}
<div id="agrid">
@grid.GetHtml(
tableStyle: "webGrid",
headerStyle: "header",
alternatingRowStyle: "alt",
columns: grid.Columns(
grid.Column("ID"),
grid.Column("Description")
)
)
</div>
控制器:
public ActionResult Index(int? page=1, int currentPage = 1, int PageSize = 10, string SortColumn = "", string SortOrder = "", string SearchString = "", int numberOfPages=0, int tr=0)
{
DataContextDataContext obj = new DataContextDataContext();
System.Nullable<int> Total = null;
var model = obj.TempItemSubClassList(page, PageSize, SortColumn, SortOrder, SearchString, ref Total).ToList();
tr = (int) Total;
numberOfPages = (int)(Total + PageSize - 1) / PageSize;
return View(model);
//var itemsubclasses = db.ItemSubClasses.Include(i => i.ItemClass);
//return View(itemsubclasses.ToList());
}