2014-03-02 21 views
0

好日子每個人,我使用MvcJqGrid(https://github.com/robinvanderknaap/MvcJqGrid)來顯示我的數據在我的項目。我想通過jquery post傳遞當前的jqgrid設置,但我無法在動作控制器中獲取它。看起來我錯過了GridModelBinder的一些東西。你能告訴我我在做什麼錯在這裏..感謝返回mvcjqgrid gridsettings到行動控制器通過jquery後不工作

這是我的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"); 
} 

回答

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 
} 
相關問題