Good Day Everyone, I'm using MvcJqGrid(https://github.com/robinvanderknaap/MvcJqGrid) to display my data in my project. I'm trying to pass the current jqgrid settings by jquery post, but i am not able to get it in the action controller. it seems I'm missing something for the GridModelBinder. can you tell me what am i doing wrong here.. thanks
This is my javascript code:
function Export() {
var data = $("#ReportGrid").getGridParam("postData");
$.post('/Home/ExporttoExcel', { gridSettings: data, moduleID: 3 });
}
and this is my action controller:
public FileContentResult ExporttoExcel(GridSettings gridSettings, Int32 moduleID = 0)
{
///Do something with the gridsettings value here.
var encoding = new ASCIIEncoding();
var fileContent = encoding.GetBytes(file.ToString());
return File(fileContent, "application/ms-excel", "List.xls");
}
I resolve this one by just passing the search values from the jqgrid and deserialize it in the controller.
my javascript looks like this:
function ajaxExport() {
var data = $("#ReportGrid").getGridParam("postData");
location.href = "/Home/ExporttoExcel?issearch=" + data._search + "&where=" + data.filters;
}
my Action method:
public ActionResult ExporttoExcel(String issearch, String where = "")
{
var jserializer = new JavaScriptSerializer();
GridSettings settings = new GridSettings();
if (where != "")
{
MvcJqGrid.Filter f = jserializer.Deserialize<MvcJqGrid.Filter>(where);
settings = new GridSettings()
{
IsSearch = issearch == "true" ? true : false,
PageIndex = 1,
PageSize = 10000,
SortColumn = "",
SortOrder = "asc",
Where = new MvcJqGrid.Filter()
{
groupOp = f.groupOp,
rules = f.rules
}
};
}
//Do my stuff here. Use the where conditions to query my DB
}