Here is what I did:
In the controller, I set try catch:
try { //model = getmodelfromdb(); return View("MyView", model); } catch (Exception ex) { Elmah.ErrorSignal.FromCurrentContext().Raise(ex); return View("../Error/ShowException", ex); }
For custom view for 404, I did this in global.asax:
protected void Application_OnError( ) { var exception = Server.GetLastError( ); Elmah.ErrorSignal.FromCurrentContext().Raise(exception); Helper.SetSessionValue(SessionKeys.EXCEPTION, exception); Response.Redirect( "~/Error/ShowException"); }
For jqgrid, I did this in my controller:
[HttpPost] public ActionResult ListRecords( int page , DateTime? fromdate , DateTime? todate) { try { var list = FetchListFromDB(); var result = new { total = Math.Ceiling(list.Count / (decimal)Helper.PAGE_SIZE), page = page,
And this is in the view (in the jqgrid definition):
loadComplete:function(data) { if (data.errorMessage) { alert(data.errorMessage); } },
In ajax common scenario:
success: function(data) { if (data.errorMessage) { alert(data.errorMessage); } else {
source share