title: handle errors thrown by OnResultExecuted
body: <p>I've implemented an <code>ActionFilterAttribute</code> responsible for NHibernate transaction management.  Transactions are committed in the <code>OnResultedExecuted</code> override, which occasionally will result in an exception being thrown.</p>
  
  <p>I'm able to successfully intercept these exceptions in the controllers <code>OnException</code> override, however the page still redirects as if the transaction were successful.</p>
  
  <p>What I'd like to be able to do is return the same view action that caused the error with the exceptions message added to the <code>ModelState</code>.</p>
  
  <p>I've tried a number of different things, none of which seem to work..  here's my latest attempt:</p>
  
  <pre><code>[HttpPost]
  [Transaction]
  [HandleError]
  public ActionResult Enroll(EnrollNewEmployeeCommand command)
  {
      if(command.IsValid())
      {
          try
          {
              _commandProcessor.Process(command);
          }
          catch(Exception exception)
          {
              ModelState.AddModelError("", exception.Message);
              return View(command);
          }
          return this.RedirectToAction(x =&gt; x.Index());  // redirects to index even if an error occurs
      }
      return View(command);
  }
  
  
  protected override void OnException(ExceptionContext filterContext)
  {
      //dont interfere if the exception is already handled
      if (filterContext.ExceptionHandled)
          return;
  
      ModelState.AddModelError("", filterContext.Exception.Message);
  
      filterContext.ExceptionHandled = true;
  
      // want to return original view with updated modelstate
      filterContext.Result = new ViewResult
      {
          ViewName = filterContext.RequestContext.RouteData.Values["action"].ToString(),
          ViewData = filterContext.Controller.ViewData
      };
  }
  </code></pre>