Click here to Skip to main content
15,891,629 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.
Posted
Updated 15-Jul-14 1:44am
v2

1 solution

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();');
                   $('#YourParentDivIDWherePartialIsRendered').undelegate();
                   $('#YourParentDivIDWherePartialIsRendered').html(data);
                   $(document).foundation();
               },
               error: function (xhr, status, error) {
                   alert(error);
               }

           });
 
Share this answer
 
Comments
Suraj Kumar -Member 11229894 13-Apr-16 2:18am    
How to sorting the table using Webgrid because when I want to sort the table it again Fire the Default controller action method. In my Controller action method some insertion method is there..When i want to sort then it after data insertion it is sorting, but I want only the Grid should be Updated. How plz assist me.. Soon ..

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900