title: TempData & Redirect for Errors
body: <p>I have a controller action in my project that has a situation where it needs to display an error message to the user under certain scenarios. This action occurs in a POST:</p>
  
  <pre><code>[HttpPost]
  public ActionResult DoSomeAction() {
      if( someCondition )
          return RedirectToAction("SomeActionError");
  
      return RedirectToAction("Index");
  }
  
  public ActionResult SomeActionError() {
      return View();
  }
  </code></pre>
  
  <p>Currently I have it set up so that it will redirect to an error controller action. I'm not really fond of this approach because in the URL they see <code>/SomeActionError</code> and it also means that the user can directly navigate to this URL.</p>
  
  <p>Is it a bad design/approach to put some flag in TempData and redirect to another controller that checks for the TempData error flag?</p>
  
  <p>Example:</p>
  
  <pre><code>[HttpPost]
  public ActionResult DoSomeAction() {
      if( someCondition ) {
          TempData["DoSomeActionError"] = true;            
      }
  
      return RedirectToAction("Index");
  }
  
  public ActionResult Index() {
      // check for error
      if( TempData["DoSomeActionError"] ) {
          return View("SomeActionError");
      }
  }
  </code></pre>
  
  <p>Is this a bad idea? Is there another approach that does something similar (doesn't allow the user to directly navigate to the error action)? I don't want to return the View on the POST action because I don't want them to refresh and cause another POST.</p>