2012-05-05 47 views
1

獲取,編輯和刪除全部正常工作。但添加不會調用我的ActionResult方法。我正在使用內聯添加,它爲新記錄值顯示模態窗體。在最新的jqGrid版本中提供的pager/form方法似乎很少有這樣的例子。我在這裏添加/插入錯過了什麼?jqGrid添加行不起作用

HTML:

  $("#grid").jqGrid({ 
       url: 'ABC.Admin/CourseAdmin/GetLocationData/', 
       datatype: 'json', 
       jsonReader: { repeatitems: false }, 
       mtype: 'GET', 
       colNames: ['Location Id', 'Name', 'Address Line 1'], 
       colModel: [ 
       { name: 'LocationId', index: 'LocationId', width: 40, key: true }, 
       { name: 'LocationName', index: 'LocationName', width: 150, editable: true }, 
       { name: 'AddressLine1', index: 'AddressLine1', width: 150, editable: true }, 
       ], 
       pager: jQuery('#pager'), 
       rowNum: 20, 
       sortname: 'Name', 
       sortorder: "asc", 
       viewrecords: true, 
       caption: '***Testing***', 
       height: 200, 
       loadonce: true, // needs to be true for client side paging to work 
       autowidth: true, 
       loadtext: 'Loading...' 
      }) 
      $("#grid").jqGrid('navGrid', '#pager', { edit: true, add: true, del: true }, 
      { // edit options 
       url: 'ABC.Admin/CourseAdmin/SaveLocation/', 
       closeAfterEdit: true 
      }, 
      { // add 
       url: 'ABC.Admin/CourseAdmin/Create/' 
      }, 
      { //delete 
       url: 'ABC.Admin/CourseAdmin/DeleteLocation/', 
       closeOnEscape: true 
      } 
     ); 

控制器:

公衆的ActionResult創建(INT ID,字符串LOCATIONNAME,串addressLine1)

[HttpPost] 
public ActionResult CreateLocation(string oper, string id, string locationName, string addressLine1)  { 
      //Models.LocationProvider lp = new Models.LocationProvider(); 
      //bool saved = lp.InsertLocation(location); 
      bool saved = false; 
      if (!saved) 
      { 
       Response.StatusCode = 500; 
       return Content("Record not saved!"); 
      } 
      else 
      { 
       return Json(false); 
      } 
     } 

回答

0

我得到了它的工作。 Create方法sig中參數的類型不匹配。他們需要成爲所有的字符串。將我的控制器更改爲以下作品。我也注意到,IDOPER PARAMS由名稱,而不是爲了拾起 - 這樣我就可以把他們在第一或最後一個(或地方)的簽名,他們得到了正確的價值觀 - 爽!我將使用此更正編輯我的原始帖子。

 public ActionResult Create(string oper, string id, string locationName, string addressLine1) 

爲別人尋找的jqGrid添加/插入的例子,我希望這一個幫助了。