gpt4 book ai didi

jquery - 错误状态: 'Internal Server Error' .错误代码:MVC4 JQgrid编辑和删除中的500

转载 作者:行者123 更新时间:2023-12-01 05:51:26 24 4
gpt4 key购买 nike

嗨,我开始在 JQgrid 上工作,它对于添加、搜索等都工作得很好,但是当我删除记录时,它会获取我的错误,正如我的帖子所说。它没有进入删除和编辑 Controller 操作本身,我通过在其中放置断点进行检查。我的代码看起来像看法{

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

}

我的 Controller 看起来像{

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

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

最佳答案

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

关于jquery - 错误状态: 'Internal Server Error' .错误代码:MVC4 JQgrid编辑和删除中的500,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21854022/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com