加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net-mvc-3 – MVC3 razor Webgrid分页和排序超过2000条记录

发布时间:2020-12-16 03:22:01 所属栏目:asp.Net 来源:网络整理
导读:我正在使用类似于 here提到的webgrid @{ var grid = new WebGrid(canPage: true,rowsPerPage: ThisController.PageSize,canSort: true,ajaxUpdateContainerId: "grid"); grid.Bind(Model.Employees,rowCount: Model.TotalRecords,autoSortAndPage: false); g
我正在使用类似于 here提到的webgrid

@{
    var grid = new WebGrid(canPage: true,rowsPerPage: ThisController.PageSize,canSort: true,ajaxUpdateContainerId: "grid");
    grid.Bind(Model.Employees,rowCount: Model.TotalRecords,autoSortAndPage: false);
    grid.Pager(WebGridPagerModes.All);
    @grid.GetHtml(htmlAttributes: new { id="grid" },columns: grid.Columns(
            grid.Column(format: (item) => Html.ActionLink("Edit","Edit",new { EmployeeID = item.EmployeeID })),grid.Column("FullName"),grid.Column("Title")
        ));
}

但在我的情况下,我期待超过2000条记录,我想加载每页只加载50条记录,以便页面加载速度更快.如何确保在加载页面时仅加载前50条记录.当我的用户单击page2时,我想加载下一组50条记录,依此类推.
你们中的任何人都遇到过类似的问题,请给我一些示例代码

解决方法

这篇MSDN杂志文章展示了你想要的东西:

Get the Most out of WebGrid in ASP.NET MVC

阅读本节:添加分页和排序

As you can see,the data we’re passing contains the full list of products (295 of them in this example,but it’s not hard to imagine scenarios with even more data being retrieved). As the amount of data returned increases,you place more and more load on your services and databases,while still rendering the same single page of data. But there’s a better approach: server-side paging. In this case,you pull back only the data needed to display the current page (for instance,only five rows).

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读