Objective:
I want to pass an object of type Kendo.Mvc.UI.DataSourceRequest
to the Mvc action, so that i can get the results from database according to the sorting and filtering applied.
Problem/Obstacle: The object gets null when it reaches to 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 to JSON.stringify but still the same
and also like var datatoPost = "{'request': '" + JSON.stringify(gridDatasource) + "', 'TotalRec': '" + 100 + "'}";
Do i need to parse my object here or may be convert its type.
For me worked the following:
$("#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!");
}
);
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With