0

大家好,我正在使用 MvcJqGrid(https://github.com/robinvanderknaap/MvcJqGrid)在我的项目中显示我的数据。我正在尝试通过 jquery post 传递当前的 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");
}
4

1 回答 1

0

我通过从 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
}
于 2014-04-20T13:18:27.000 回答