2012-12-24 35 views
0

嘿,堆棧溢出愛好者。我有一個jqGrid網格,我想從JSON數據填充到viewData存儲庫中。我怎樣才能做到這一點?從viewData獲取jqGrid數據:使用jqgrid.htmlEncode?

到目前爲止,我只有這... 更新:現在我想打一個控制器的方法,而不是通過可視數據向上傳遞數據

$("#results").jqGrid({ 
     shrinkToFit: false, 
     autowidth: false, 
     width: 800, 
     datatype: 'jsonsstring', 
     url:'<%=Url.Action("getGrid", "Log", new { physSearch = Model})%>', 
     //datastr: $.jgrid.htmlEncode('@ViewData["ResultData"]'), 
     mtype: 'POST', 
     colNames: 
      [ 
       'Sent Time', 
       'Recipient', 
       'EPCD ID', 
       'Address', 
       'Channel', 
       'Sent Status', 
       'Document ID', 
       'MRN', 
       'Patient Name', 
       'Pages', 
       'Message Log ID', 
       'Orginial Message Log ID', 
       'Message ID', 
       'Message Type', 
       'Sender', 
       'Comments' 
      ], 
     colModel: 
      [ 
       { name: 'Sent_Time', width: 115 }, 
       { name: 'Recipient', width: 115 }, 
       { name: 'EPCD_ID', width: 115 }, 
       { name: 'Address', width: 115 }, 
       { name: 'Channel', width: 115 }, 
       { name: 'Sent_Status', width: 115 }, 
       { name: 'Document_ID', width: 115 }, 
       { name: 'MRN', width: 115 }, 
       { name: 'Patient_Name', width: 115 }, 
       { name: 'Pages', width: 115 }, 
       { name: 'Message_Log_ID', width: 115 }, 
       { name: 'Orginial_Message_Log_ID', width: 115 }, 
       { name: 'Message_ID', width: 115 }, 
       { name: 'Message_Type', width: 115 }, 
       { name: 'Sender', width: 115 }, 
       { name: 'Comments', width: 115 } 
      ], 
     rowNum: 10, 
     rowList: [5, 10, 20, 50], 
     sortname: 'Id', 
     sortorder: "desc", 
     loadui: 'block', 
     loadtext: 'Results Grid',viewrecords: true, 
     imgpath: '/Content/themes/UPMC-theme/images', 
     caption: 'Patient Return Result', 
     ondblClickRow: function (id) { } 
    }) 

回答

1

嘗試這樣的:

datatype: 'json', 
datastr: @Html.Raw(Json.Encode(ViewData["ResultData"])) 
+0

嘿Darin。我想我可能會試着打一個控制器方法,而不是通過視圖數據傳遞數據......我正在調試使用chrome可能會做錯的事情,我會在第二時間回覆你。 – SoftwareSavant

+0

是的,當然,如果你願意,你可以使用AJAX填充一個jqGrid。因此,您將有一個控制器操作返回JSON數據,並且它們只是指示jqGrid從此操作中獲取數據(使用「url」開關)。請繼續閱讀jqGrid文檔 - 您需要知道的所有內容都在這裏解釋。並且也是例證。 –