title: How to pass error message to error view in MVC 5?
body: <p>I am working on exception handling and have written below code for the same.</p>
  
  <p><strong>Web.Config</strong> </p>
  
  <pre><code>&lt;customErrors mode="On"&gt;&lt;/customErrors&gt;
  </code></pre>
  
  <p><strong>Code Changes</strong></p>
  
  <pre><code>public class CustomExceptionFilter : HandleErrorAttribute
  {
      public override void OnException(ExceptionContext filterContext)
      {
  
          //_logger.Error("Uncaught exception", filterContext.Exception);
  
          ViewResult view = new ViewResult();
          view.ViewName = "Error";
          filterContext.Result = view;
  
          // Prepare the response code.
          filterContext.ExceptionHandled = true;
          filterContext.HttpContext.Response.Clear();
          filterContext.HttpContext.Response.TrySkipIisCustomErrors = true;
      }
  }
  </code></pre>
  
  <p><strong>Global.asax</strong> </p>
  
  <pre><code>protected void Application_Start()
  {
      AreaRegistration.RegisterAllAreas();
      FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
      RouteConfig.RegisterRoutes(RouteTable.Routes);
      BundleConfig.RegisterBundles(BundleTable.Bundles);
  
      // To handle exceptions
      GlobalFilters.Filters.Add(new CustomExceptionFilter());
  
      var unityContainer = ModelContainer.Instance;
      DependencyResolver.SetResolver(new UnityDependencyResolver(unityContainer));
  }
  </code></pre>
  
  <p><strong>Error View</strong></p>
  
  <pre><code>@*@model System.Web.Mvc.HandleErrorAttribute*@
  &lt;div class="row"&gt;
      &lt;div class="col-sm-12"&gt;
          &lt;h1&gt;Error&lt;/h1&gt;
          &lt;div class="col-sm-12"&gt;
              &lt;h2&gt;An error occurred while processing your request.&lt;/h2&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>In my error view, I want to show the exception message.</p>
  
  <p>Also I have one more requirement to show different message in case of <code>404 error</code> exists.</p>