In my ASP.NET MVC application I have an ErrorController, currently having only one action method that receives a custom class called Error and renders it to the view called Error.cshtml. For now, there're only 2 properties in the Error class:
public class Error{
public string UserFriendlyMmessage{get;set;}
public string ErrorMessage{get;set;}
}
The Error.cshtml view is strongly typed to the Error class. Whenever an exception is thrown inside an action method I do the following:
Error error = new Error { UserFriendlyText = "The friendly message", ErrorDescription = "Error to be logged" };
return RedirectToAction("Index", "Error", new System.Web.Routing.RouteValueDictionary(error));
And here's the action method of the ErrorController:
public ActionResult Index(Error error)
{
return View(model: error, viewName:"Error");
}
While this works well, this way all the model properties are shown in the url. Is there a better, more commonly used way of doing this?
Errorto aTempDataproperty, thenreturn RedirectToAction("Index", "Error")and in theIndex()method get the value fromTempdataand render the view.[HandleError()]attributes that define a custom exception type and the associated view to render, Then I might say throw anEditDeniedException("Some friendly message")and the framework automatically displays the associated view.