2010-12-02 56 views
0

我正在使用JqGrid和我的WebForms網站設置從[WebMethod()]中獲取數據。這是工作,但現在我需要獲得編輯帖子以「Application/json」的形式發回內容,但我沒有運氣。看着Fiddler,我看到帖子回到「Application/x-www-form-urlencoded」 - 我以爲我找到並設置了所有正確的選項,但它仍然是一個禁忌。Asp.net JqGrid:獲取網格的編輯帖子去Application/Json?

這裏的網格設置:

$.extend($.jgrid.edit, { 
    ajaxEditOptions: { contentType: "application/json; charset=utf-8" },   
}); 

jQuery("#<%=jqGridName%>").jqGrid({ 
     editurl: "/web/juicepress-misc-settings.aspx/saveJpUserException", 
     ajaxGridOptions: { contentType: "application/json; charset=utf-8", dataType: "json" }, 
     ajaxEditOptions: { contentType: "application/json; charset=utf-8", dataType: "json" }, 
     prmNames: { 
      search: "isSearch", 
      nd: null, 
      rows: "numRows", 
      page: "page", 
      sort: "sortField", 
      order: "sortOrder" 
     }, 
     // Default values for search to make sure that the ajax call doesn't fail 
     postData: { searchString: '', searchField: '', searchOper: '' }, 
     datatype: function(postdata) {     
      $.ajax({ 
       url: '/Web/juicepress-misc-settings.aspx/getJpUserExceptions', 
       type: "POST", 
       contentType: "application/json; charset=utf-8", 
       data: JSON.stringify(postdata), 
       dataType: "json", 
       success: function(data, st) {       
        if (st == "success") { 
         var grid = $("#<%=jqGridName%>")[0]; 
         var gridData = data.d;             
         grid.addJSONData(gridData); 
        } 
       }, 
       error: function() { 
        alert("Error with AJAX callback"); 
       } 
      }); 
     }, 
     height: <%=height %>, 
     width: <%=width %>, 
     jsonReader: {     
      id: "<%= keyDataField %>", //index of the column with the PK in it     
      repeatitems: false 
     }, 
     colNames: [ <%= getColumnHeaders() %> ], 
     colModel: [ <%= getColumns() %> ], 
     multiselect: false, 
     gridview: true, 
     ignoreCase: true, 
     caption: "<%= gridTitle %>", 
     gridComplete: function(){      
      var ids = jQuery("#<%=jqGridName%>").jqGrid('getDataIDs');      
      for(var i=0;i < ids.length;i++){ 
       var cl = ids[i];       
       be = "<input style='height:22px;width:20px;' type='button' value='E' onclick=\"jQuery('#<%=jqGridName%>').editRow('"+cl+"');\" />"; 
       se = "<input style='height:22px;width:20px;' type='button' value='S' onclick=\"jQuery('#<%=jqGridName%>').saveRow('"+cl+"');\" />";      
       jQuery("#<%=jqGridName%>").jqGrid('setRowData',cl,{act:be+se}); 
      } 
     } 
    }); 

我的服務是在頁面中[的WebMethod]裝飾方法:

[WebMethod()] 
public static void saveJpUserException(string name, string description, string oper, int id) { 
    ... 
} 

回答

0

在線顯然編輯不使用 「ajaxEditOptions」,而是使用 「ajaxRowOptions」(去圖)...

所以修復它這樣的:

ajaxRowOptions: { contentType: "application/json; charset=utf-8", dataType: "json" }