Pass Object of type "Kendo.Mvc.UI.DataSourceRequest" from jquery to Mvc Action

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.

+4
source share
1 answer

The following worked for me:

 $("#excel").kendoButton({ click: function (event) { var data = grid.dataSource._params(); var prepared = grid.dataSource.transport.parameterMap(data); $.post("/Root/AnotherControllerMethod", prepared, function (data, status, xhr) { console.log("Ok!"); } ); } }); 
+9
source

Source: https://habr.com/ru/post/1501992/


All Articles