0

皆さん、こんにちは。MvcJqGrid ( https://github.com/robinvanderknaap/MvcJqGrid ) を使用して、プロジェクトにデータを表示しています。現在の jqgrid 設定を jquery post で渡そうとしていますが、アクション コントローラーで取得できません。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 に答える