大家好,我使用MvcJqGrid(https://github.com/robinvanderknaap/MvcJqGrid)在我的项目中显示我的数据。我试图通过jquery传递当前的jqgrid设置,但是我无法在操作控制器中获得它。似乎我错过了GridModelBinder的一些东西。你能告诉我我做错什么了吗..。谢谢
这是我的javascript代码:
function Export() {
var data = $("#ReportGrid").getGridParam("postData");
$.post('/Home/ExporttoExcel', { gridSettings: data, moduleID: 3 });
}这是我的行动控制器:
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");
}发布于 2014-04-20 13:18:27
我通过从jqgrid传递搜索值并在控制器中反序列化来解决这个问题。
我的javascript如下所示:
function ajaxExport() {
var data = $("#ReportGrid").getGridParam("postData");
location.href = "/Home/ExporttoExcel?issearch=" + data._search + "&where=" + data.filters;
}我的行动方法:
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
}https://stackoverflow.com/questions/22123976
复制相似问题