I am trying to post some stringified data to an action method in my MVC controller. Below is the piece of JS Code
function SaveStateForGrid(pGridId, pIsAysnc) {
var grid = $('#' + pGridId).data("kendoGrid");
var tGridState = kendo.stringify(grid.getOptions());
$.ajax({
url: '/Home/SaveGridState',
type: 'POST',
dataType: 'json',
async: pIsAysnc,
data: { pGridState: tGridState, pGridName: pGridId },
success: function (data) {
console.log("Data Saved Successfully");
},
error: function (jqXHR, textStatus) {
console.log("Error while saving grid data " + pGridId);
}
});
}
I am trying to save gridstate info into the db and each grid in my app has different grid state info.
This works sometimes - as in, the post hits the controller method "SaveGridState" if I keep a breakpoint there and so on. On other occasions the breakpoint is not hit and the data is not saved in DB but the code does flow to "success" AJAX callback - no errors and I get a 200POST OK response in the network tab of chrome debugger.
I looked up the data being sent and figured out that on the occasions it fails, there is something about the data being posted which is causing it. Specifically the first param - "tGridState" - a stringified KendoGrid config data. If I replace this data from other successful calls, there is no issue. I have compared the data on different viewing tools and am not able to understand what in the data is breaking this.
Attaching a link to the zip file which contains both "Valid" and "Invalid" data. Any help pls ?
https://www.dropbox.com/s/whfglyk607bnd04/Downloads.zip?dl=0
Few months on from posting this - the module in question was on freeze.
I discovered that the stringified gridstate information (grid config data) included JS functions for grid related events which was causing issues in the stringified data. In fact stringification strips such functions from an object.
Somehow this was preventing me from hitting the breakpoint on the server side even if the data was posted "apparently".
So I wrote a JS function to strip all unnecessary data from my gridstate config data before stringification - and then the post works perfectly.
Voila !