我在 MVC 3 中使用 JqGrid。
当我尝试删除一行时,服务器端代码中会处理一些错误。
如何将此错误消息传递给 JqGrid?
例如,在 action 方法中:
[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
简单地创建 Action 方法的 URL
最佳答案
我找到了解决方案。
只需从 catch 块中抛出异常,JqGrid 就会捕获它!
虽然没想到!!!
喜欢:
try {
dbContext.SaveChanges();
} catch (DbUpdateException){
throw new Exception("Could not delete project.");
}
关于asp.net-mvc-3 - 在 .Net MVC3 中如何处理 JqGrid 中的服务器端错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7631913/