/// <summary> /// Displays a generic error message /// </summary> /// <param name="title"></param> /// <param name="message"></param> /// <param name="redirectTo"></param> /// <returns></returns> public ActionResult ShowError(string title, string message, string redirectTo) { if (string.IsNullOrEmpty(message)) message = "We are sorry, but an unspecified error occurred in the application. The error has been logged and forwarded to be checked out as soon as possible."; ErrorViewModel model = new ErrorViewModel { Message = message, Title = title, RedirectTo = redirectTo != null ? Url.Content(redirectTo) : "", MessageIsHtml = true }; // Explicitly point at Error View regardless of action return View("Error", model); }
/// <summary> /// Static method that can be called from outside of MVC requests /// (like in Application_Error) to display an error View. /// </summary> public static void ShowErrorPage(ErrorViewModel errorModel) { ErrorController controller = new ErrorController(); RouteData routeData = new RouteData(); routeData.Values.Add("controller", "Error"); routeData.Values.Add("action", "ShowErrorFromModel"); routeData.Values.Add("errorModel", errorModel); ((IController)controller).Execute(new RequestContext(new HttpContextWrapper(System.Web.HttpContext.Current), routeData)); }
/// <summary> /// Displays a generic error message but allows passing a view model directly for /// additional flexibility /// </summary> /// <param name="errorModel"></param> /// <returns></returns> public ActionResult ShowErrorFromModel(ErrorViewModel errorModel) { return View("Error", errorModel); }
/// <summary> /// Displays a generic error message but allows passing a view model directly for /// additional flexibility /// </summary> /// <param name="errorModel"></param> /// <returns></returns> public ActionResult ShowErrorFromModel(ErrorViewModel errorModel) { return(View("Error", errorModel)); }