public ActionResult Index(ErrorViewModel error_model) { if (error_model != null && error_model.ErrorModel != null) { return View(error_model); } return RedirectTo<HomeController>(a => a.Index()); }
/// <summary> /// Обработка ошибок в приложении. /// </summary> protected void Application_Error() { Response.Clear(); Response.StatusCode = 503; var lastException = Server.GetLastError(); var exception = lastException as HttpException; if (exception != null) { Response.StatusCode = exception.GetHttpCode(); } var errorController = new ErrorController(NinjectMVC3.Kernel.Get<IDIKernel>()); var model = new ErrorViewModel { ErrorModel = new ErrorModel { Message = lastException. Message, Code = Response.StatusCode } }; var routeData = new RouteData { Values = { {"controller", "Error"}, {"action", "Index"}, { "error_model", model } } }; var requestContext = new RequestContext(new HttpContextWrapper(Context), routeData); var controllerContext = new ControllerContext(requestContext, errorController); var viewResult = errorController.Index(model); viewResult.ExecuteResult(controllerContext); Server.ClearError(); }