Exemplo n.º 1
0
        /// <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);
        }
Exemplo n.º 2
0
        /// <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));
        }
Exemplo n.º 3
0
 /// <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);
 }
Exemplo n.º 4
0
 /// <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));
 }