在.Net MVC3中如何处理JqGrid中的服务器端错误?
我将 JqGrid 与 MVC 3 结合使用。
当我尝试删除行时,服务器端代码会处理一些错误。
如何将此错误消息传递给 JqGrid?
例如,在操作方法中:
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Delete(int id) {
Project project = dbContext.Projects.Find(id);
dbContext.Projects.Remove(project);
try {
dbContext.SaveChanges();
} catch (DbUpdateException){
// Send the error to JqGrid
}
return RedirectToAction("Index");
}
在 JqGrid 中:
$('#DataTable').
jqGrid('navGrid', '#pager',
{ add: true, del: true, edit: true, search: false },
{ url: Url("Edit", controllerName), closeAfterEdit: true },
{ url: Url("Create", controllerName), closeAfterAdd: true },
{ url: Url("Delete", controllerName) }
);
方法 URL
只是创建操作方法的 URL
I am using JqGrid with MVC 3.
Some errors are handled in the server side code when I am trying to delete a row.
How can I pass this error message to JqGrid?
For example, In the action method:
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Delete(int id) {
Project project = dbContext.Projects.Find(id);
dbContext.Projects.Remove(project);
try {
dbContext.SaveChanges();
} catch (DbUpdateException){
// Send the error to JqGrid
}
return RedirectToAction("Index");
}
In JqGrid:
$('#DataTable').
jqGrid('navGrid', '#pager',
{ add: true, del: true, edit: true, search: false },
{ url: Url("Edit", controllerName), closeAfterEdit: true },
{ url: Url("Create", controllerName), closeAfterAdd: true },
{ url: Url("Delete", controllerName) }
);
the method URL
simply creates the URL to the action method
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我找到了解决方案。
只需从 catch 块中抛出异常,JqGrid 就会捕获它!
虽然我没想到!!!
喜欢:
I found the solution.
Just throw the exception from the catch block and JqGrid will catch it!
I did not expect it though!!!
Like: