错误状态:'内部服务器错误'。错误代码:MVC4中的500 JQgrid编辑和删除

时间:2014-02-18 12:34:14

标签: jquery asp.net-mvc entity-framework jqgrid mvcjqgrid

您好我开始使用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);
            }
}

}  请建议我解决这个问题的方法。

1 个答案:

答案 0 :(得分:0)

使用Firefox / Firebug或IE8开发人员工具查看从服务器获得的实际响应。它会落在哪条线上?一旦你发现,你可能会发现你的错误。