MVC4的WebGrid和Ajax分页 [英] MVC4 WebGrid and Ajax Pagination

查看:282
本文介绍了MVC4的WebGrid和Ajax分页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a simple question (may not be a simple answer!) with the WebGrid in MVC4.

我有一个功能网格像这样

I have a functional Grid like so

<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>

在重装提交分区与阿贾克斯点击翻页按钮时,它产生下一个页面细 - 但它要在控制器上原有的作用,这应该是一个完整的页面

When reloading the "Submitted" div with Ajax when the next page button is clicked, it generates the next page fine - but it's going to the original action on the controller, which should be a full page.

它是如何过滤掉一切不是网格本身其他?一些聪明的C#code或jQuery的?

How does it filter out everything other than the grid itself? with some clever C# code or jQuery?

编辑: 为了澄清,我不是问怎么做分页比较好,还是我自己,就我而言,默认页面的的WebGrid是正常使用,因为它应该 - 我问的WebGrid是怎么做的Ajax分页时,回发到返回一个完整页面的操作。

To clarify, I'm not asking how to do the paging better, or myself, as far as I'm concerned the default paging with the webgrid is working perfectly as it should - I'm asking how the WebGrid does it's ajax paging when posting back to an action which is returning a FULL page.

推荐答案

为此,它使用jQuery的load()和功能,使其只选择相关的传入节点。这是从 http://msdn.microsoft.com/en-us/magazine /hh288075.aspx

It does this using jquery load() and functionality that allows it to select just the relevant incoming nodes. This is taken from http://msdn.microsoft.com/en-us/magazine/hh288075.aspx

要允许脚本应用只是一个的WebGrid,它使用jQuery选择器来识别与ajaxGrid类集合中的元素。该脚本确立点击处理程序使用jQuery活法(api.jquery.com/live)排序和分页链接(通过表的页眉或页脚电网容器内确定)。这将设置的事件处理程序相匹配的选择,这是很方便的给定的脚本将被替换的内容,现有的和未来的元素。

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.

这篇关于MVC4的WebGrid和Ajax分页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆