c# - MVC4 WebGrid 和 Ajax 分页

标签 c# jquery ajax asp.net-mvc asp.net-mvc-4

我有一个关于 MVC4 中的 WebGrid 的简单问题(可能不是一个简单的答案!)。

我有一个像这样的功能网格

<div id="Submitted">
    @Html.Grid(
        Model.Submitted, displayHeader: false, fieldNamePrefix: "Submitted_", ajaxUpdateContainerId: "Submitted",
        columns: new WebGridColumn[]{
        new WebGridColumn(){ ColumnName = "Date",Header = "Date",Style = "",CanSort = false,Format = x => x.Date.ToString(Globals.Default.DATEFORMAT) },
        new WebGridColumn(){ ColumnName = "ID",Header = "Review",Style = "", CanSort = false, Format = x=>@Html.ActionLink("Review","Review","Company",new{ID = x.ID },new{})  }
    })
</div>

当单击下一页按钮时使用 Ajax 重新加载“已提交”div 时,它会很好地生成下一页 - 但它会转到 Controller 上的原始操作,这应该是一个完整的页面。

它如何过滤除网格本身以外的所有内容?使用一些聪明的 C# 代码或 jQuery?

编辑: 澄清一下,我不是在问如何更好地进行分页,也不是在问我自己,就我而言,webgrid 的默认分页可以正常工作——我是在问 WebGrid 是如何进行 ajax 分页的回发到返回完整页面的操作。

最佳答案

它使用 jquery load() 和允许它仅选择相关传入节点的功能来执行此操作。这取自 http://msdn.microsoft.com/en-us/magazine/hh288075.aspx

To allow the script to be applied just to a WebGrid, it uses jQuery selectors to identify elements with the ajaxGrid class set. The script establishes click handlers for the sorting and paging links (identified via the table header or footer inside the grid container) using the jQuery live method (api.jquery.com/live). This sets up the event handler for existing and future elements that match the selector, which is handy given the script will be replacing the content.

关于c# - MVC4 WebGrid 和 Ajax 分页,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14514686/

相关文章:

c# - XML-RPC Odoo - C# 多个搜索条件

c# - 单元测试、Linq to SQL 和围绕数据上下文工作

javascript - 点击视频替换图片

javascript - 从纯 Javascript 发送 PUT 到 Laravel Controller

c# - 按位归零在结构构造中意味着什么?

c# - 如何使用 WebDav 在 C# 中访问 nextcloud 文件?

Jquery 如果悬停元素添加按钮 如果不删除按钮

javascript - 使用整数或分数值将 px 转换为 mm

php - Ajax/PHP/MySQL 和运行代码

ajax - jQuery扩展ajax参数