Purpose: I want to pass an object of type Kendo.Mvc.UI.DataSourceRequest
to an Mvc action so that I can get the results from the database according to the sorting and filtering applied.
Problem / Obstruction: The object gets null when it reaches the action.
MY Controller action
public ActionResult Getresults([DataSourceRequest]DataSourceRequest request, Int32 TotalRec) { try { //get data from DAL var result = new DataSourceResult() { Data = List, // Process data (paging and sorting applied) Total = TotalRec }; return Json(result, JsonRequestBehavior.AllowGet); } catch (Exception ex) { throw ex; } }
My jquery function
function getData() { var gridDatasource = $('#gridname').data('kendoGrid').dataSource.options; var datatoPost = "{'request': '" + JSON.stringify(new kendo.data.DataSource(gridDatasource)) + "', 'TotalRec': '" + 100 + "'}"; //new kendo.data.DataSource $.ajax({ type: "Post", url: '/Administrator/Getresults/', contentType: "application/json; charset=utf-8", data: datatoPost, dataType: "json", processdata: false, success: function (value) { alert(value.d); }, error: function () { alert("Ajax Error"); } }); }
I tried JSON.stringify, but still the same as well as var datatoPost = "{'request': '" + JSON.stringify(gridDatasource) + "', 'TotalRec': '" + 100 + "'}";
I need to analyze my object here or it can be transformed.
source share