错误状态:'内部服务器错误'。错误代码:500在MVC4中JQgrid编辑和删除 [英] error Status: 'Internal Server Error'. Error code: 500 in MVC4 JQgrid Edit and Delete

查看:212
本文介绍了错误状态:'内部服务器错误'。错误代码:500在MVC4中JQgrid编辑和删除的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我开始使用JQgrid,它可以正常添加,搜索和所有,但是当我删除记录时,我的帖子告诉我错误。
它没有进入删除和编辑控制器操作本身,我通过在那里提供断点检查。
我的代码看起来像
查看
{

Hi i started working on JQgrid, and it works fine for add,search and all, but when i delete the record its fetching me the error as my post says. its not entering to the delete and edit controller action itself, i checked by putting break points in there. My code looks like View {

  <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>

}

,我的控制器看起来像
{

and my controller looks like {

   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);
            }
}

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

} please suggest me the way to solve this.

推荐答案

使用的Firefox / Firebug的或IE8的开发者工具来看看你是从服务器获取实际响应。它在哪一行呢?一旦你发现,你可能会发现你的错误。

Use Firefox/Firebug or the IE8 developer tools to look at the actual response you are getting from the server. On what line does it fall over? Once you find out, you'll probably find your error.

这篇关于错误状态:'内部服务器错误'。错误代码:500在MVC4中JQgrid编辑和删除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆