簡體   English   中英

按模型和計數分頁webgrid

[英]Paging a webgrid by Model and Count

我一直在開發一個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的尋呼機未顯示在我的視圖中。 我可以設置任何財產嗎?

由於您在模型中進行分頁,因此您應該添加:

autoSortAndPage: false

你的grid.Bind()所以它讀取:

grid.Bind(rowCount: Model.Total, source: Model.List, autoSortAndPage: false);

這應該能夠以你想要的方式在頁腳中進行分頁。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM