我一直在开发一个 asp.net mvc 3 应用程序,我正在使用 webgrid 在我的视图中显示表格数据。我的问题是,如何通过计算数据库中有多少条记录来分页某些数据并在我的网格页脚中显示 webgrid 的寻呼机?例如,在我的存储库中,我有:
public PagedList<Acesso> ObterAcessos(long idPessoa, int pageIndex, int pageSize)
{
return new PagedList<Acesso>
{
PageIndex = pageIndex,
PageSize = pageSize,
Total = Session.QueryOver<Acesso>().Where(acesso => acesso.Pessoa.Id == idPessoa).FutureRowCount(),
List = Session.QueryOver<Acesso>()
.Where(acesso => acesso.Pessoa.Id == idPessoa)
.OrderBy(acesso => acesso.DataInicio).Desc
.Take(pageSize).Skip((pageIndex - 1)*pageSize)
.Future<Acesso>()
};
}
我的控制器:
public ActionResult Acessos(int page = 1)
{
// 30 records per page
return View(_rep.ObterAcessos(SecurityHelper.User.Id, page, 30));
}
我的观点:
@model PagedList<Acesso>
@{
ViewBag.Title = "Acessos";
var grid = new WebGrid(rowsPerPage: Model.PageSize, canSort: false, ajaxUpdateContainerId: "grid");
// set the rowCount by Total property and the List property
grid.Bind(rowCount: Model.Total, source: Model.List);
}
<h2>Acessos</h2>
@grid.GetHtml(htmlAttributes: new { id="grid", style="width:700px;" },
mode: WebGridPagerModes.All,
tableStyle: "grid", rowStyle: "gridrow", alternatingRowStyle: "gridrow_alternate",
columns: grid.Columns(
grid.Column("DataInicio", "Data de Inicio", item => item.DataInicio.ToString("dd/MM/yyyy HH:mm")),
grid.Column("IP", "IP"))
)
数据正确,计数和列表正确,但是当我运行此代码时,它不会分页数据,它仅显示第一页,并且 webgrid 的分页器未显示在我的视图中。有什么我可以设置的属性吗?