1

这是我认为的代码。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());

    }
4

1 回答 1

3

网格需要知道在您提供的示例中已硬编码为 20 的总行数。将总数添加到您的模型并以这种方式引用它。此外,有点违反直觉,autoSortAndPage参数应设置为false

@{        
var grid = new WebGrid(null,
        defaultSort: "",
        rowsPerPage: 10,
        selectionFieldName:"SearchString",
        ajaxUpdateContainerId:"agrid",
        sortFieldName:"SortColumn",
        sortDirectionFieldName:"SortOrder");
grid.Bind(Model, autoSortAndPage: true, rowCount:20); <--- total number of rows
}
于 2014-02-25T23:26:23.227 回答