在webgrid中多次调用控制器以进行ajax排序和分页 [英] Multiple calls to controller in webgrid for ajax sorting and paging

查看:59
本文介绍了在webgrid中多次调用控制器以进行ajax排序和分页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在mvc4 razor视图中使用webgrid。我有多个标签,每个标签包含webgrid。我已经为每个webgrid使用了部分视图。它在ajax排序和分页以及过滤方面都运行良好。但是在ajax调用过滤之后,并且在标签索引改变之后它开始多次调用控制器。详细说明当网格第一次加载其工作正常时,具有分页和排序功能。在我尝试排序或过滤后过滤。它开始向控制器发送多个调用。

解决方案

我已经为MVC 5解决了这个问题,你需要使用ajax调用而不是使用ajax形式,

捕获ajax响应并使用下面的webgrid助手替换部分页面的DOM,




 


.ajax

{
contentType:application / json; charset = utf-8,
type:' POST',
url:'/ YourController_Name / YourAction_Name',
data:JSON.stringify(YourModel),
success:function(data){
//添加到undelegate the标记为局部视图网格的旧事件。
var data = data.replace('< script type =text / javascript>','< script type =text / javascript>

( 表)undelegate(););

I am using webgrid in mvc4 razor view. I have multiple tabs each tab contain webgrid. I have used partial view for each webgrid. it's working fine with ajax sorting and paging and also for filtering. But after ajax call filtration, and after tab index changing it's starting multiple calls to controller. In detail when grid loads first time its working fine with paging and sorting functionality. And after filter when I am trying to sort or filter. It starts sending multiple calls to controller.

解决方案

I have solved this for MVC 5, you would need to use ajax call rather than using the ajax form,
catch the ajax response and replace the partial page's DOM generated by the webgrid helper using below,



.ajax ( { contentType: "application/json; charset=utf-8", type: 'POST', url: '/YourController_Name/YourAction_Name', data: JSON.stringify(YourModel), success: function (data) { //Added to undelegate the old events tagged to the partial view's grid. var data = data.replace('<script type="text/javascript">', '<script type="text/javascript">


(".table").undelegate();');


这篇关于在webgrid中多次调用控制器以进行ajax排序和分页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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