gpt4 book ai didi

c# - MVC4 WebGrid 和 Ajax 分页

转载 作者:行者123 更新时间:2023-11-30 17:07:27 25 4
gpt4 key购买 nike

我有一个关于 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com