I am writing an ASP.NET MVC application and I ran into the following problem. I want to create custom error pages with detailed error information (for example, an error message or which controller caused the error), but I cannot provide the model in the view with the HandleErrorInfo object.
First, I configured the Web.config file to handle user errors:
<customErrors mode="On" defaultRedirect="~/Error"> <error statusCode="404" redirect="~/Error/NotFound"/> </customErrors>
Then I created an error controller to manage the error views:
public class ErrorController : Controller { public ActionResult Index() { return View("Error"); } public ViewResult NotFound() { Response.StatusCode = 404; return View("NotFound"); } }
And in the view, I added the model type:
@model System.Web.Mvc.HandleErrorInfo
But the model is null every time, and I donβt know how to pass the correct object with error data to the view and where this object should be created. Can you help me? Is it possible to do so?
asp.net-mvc error-handling
Roman suska
source share