2014-02-18 50 views
2

嗨,我開始在JQgrid的工作,並且它適用於添加,搜索和所有,但是當我刪除記錄它提取我的錯誤,因爲我的帖子說。 它沒有進入刪除和編輯控制器操作本身,我通過在那裏放置斷點來檢查。 我的代碼看起來像 查看 {錯誤狀態:'內部服務器錯誤'。錯誤代碼:500在MVC4 JQgrid編輯和刪除

<table id="jQGridDemo"> 
    </table> 
    <div id="jQGridDemoPager"> 
    </div> 
    <script type="text/javascript"> 
      jQuery("#jQGridDemo").jqGrid({ 
       url: 'RTGUser/GetUserDetails', 
       datatype: "json", 
       colNames: ['Id', 'Name', 'Designation', 'City'], 
       colModel: [ 
      { name: 'Id', index: 'Id', width: 40, align:'center', sortable: true, editable:false}, 
       { name: 'Name', index: 'Name', width: 40, align: 'center', sortable: true, editable: true, edittype: 'text', editrules: { required: true} }, 
       { name: 'Designation', index: 'Designation', width: 400, align: 'center', sortable: true, editable: true, edittype: 'text', editrules: { required: true} }, 
       { name: 'City', index: 'City', width: 150, align: 'center', sortable: true, editable: true, edittype: 'text', editrules: { required: true} } 
       ], 

      mtype: 'POST', 
      loadonce: true, 
      rowList: [5,10, 20, 30], 
      pager: '#jQGridDemoPager', 
      sortname: 'Id', 
      viewrecords: true, 
      sortorder: 'desc', 
      caption: "List Of Users" 

     }); 

     jQuery("#jQGridDemo").jqGrid('navGrid', '#jQGridDemoPager', 
     { edit: true, add: true, del: true, search:true }, 
      { url: "/RTGUser/EditUser", closeAfterEdit: true, beforeShowForm: function (formid) { $("#Id", formid).hide(); } }, 
      { url: "/RTGUser/AddNewUser", closeAfterAdd: true, beforeShowForm: function (formid) { $("#Id", formid).hide(); } }, 
      { url: "/RTGUser/DeleteUser" }, {}); 

     $("#search").filterGrid("#grid", { 
      gridModel: false, 
      filterModel: [{ 
       label: 'Search', 
       name: 'search', 
       stype: 'text' 
      }] 
     }); 

    </script> 
</body> 

}

和我的控制器看起來像 {

public ActionResult EditUser(int userId, string name, string desig, string city) 
     { 
      try 
      { 
       var query = from u in db.Users 
          where u.Id.Equals(userId) 
          select u; 

       var user = query.First(); 
       user.Name = name; 
       user.Designation = desig; 
       user.City = city; 
       db.SaveChanges(); 

       return Json(true); 
      } 
      catch (Exception) 
      { 
       // Do some error logging stuff, handle exception, etc. 
       return Json(false); 
      } 
     } 

    public ActionResult DeleteUser(int userId) 
     { 
      try 
      { 
       var query = from u in db.Users 
          where u.Id.Equals(userId) 
          select u; 

       // var user = query.First(); 
       var usr = db.Users.Find(Convert.ToInt32(userId)); 
       db.Users.Remove(usr); 
       db.SaveChanges(); 

       return Json(true); 
      } 
      catch (Exception e) 
      { 
       // Do some error logging stuff, handle exception, etc. 
       Response.Write(e); 
       return Json(false); 
      } 
} 

} 請建議我解決這個問題的方法。

回答

0

使用Firefox/Firebug或IE8開發人員工具查看您從服務器獲得的實際響應。它跌倒在哪條線上?一旦你發現,你可能會發現你的錯誤。

相關問題