Tuesday, November 18, 2014

Posting JSON data via jQuery to ASP .NET MVC 4 controller action not working



The grid data if I want to save data in json call then if the json data cross the limit of JsonDeserializer then it will not work on controller action. 




  function SaveMenuPrivilege() {  
     var postUrl;  
     var paramValue;  
     var gridData = $("#MenuPrivilegeKendoGrid").data("kendoGrid").dataSource.data();  
     // set model data   
     for (var i = 0; i < gridData.length; i++) {  
       gridData[i].NewRoleId = $("#RoleId").val();  
     }  
     postUrl = '@Url.Content("~/Admin/MenuPrivilege/SaveMenuPrivilege")';  
     paramValue = JSON.stringify({ MenuPrivilegeList: gridData }); // you can also set model data using','   
     $.ajax({  
       url: postUrl,  
       type: 'POST',  
       dataType: 'json',  
       data: paramValue,  
       contentType: 'application/json; charset=utf-8',  
       success: function (result) {  
         console.log(result);  
       },  
       error: function (objAjaxRequest, strError) {  
         var respText = objAjaxRequest.responseText;  
         console.log(respText);  
       }  
     });  
   }  


   public ActionResult SaveMenuPrivilege(MenuViewModel menuViewModel)  
     {  
      //  
     }  


 To resolve this problem you just need to add in your web config appsetting

  <add key="aspnet:MaxJsonDeserializerMembers" value="50000000" />




Ensure that this project has Microsoft.Bcl.Build installed and packages.config is located next to the project file

In my Xamarin form application their was dependency Restclient on Microsoft.Bcl.Build Microsoft.Bcl. i just remove all using nuget and ...