title: MVC temp data persists through separate page requests?
body: <p>It's been my understanding since I've been using it, that in MVC, anything you put in TempData is... well, temporary. It's only there for the duration of the current request, and then it's gone when the request is complete and the response is sent.</p>
  
  <p>In order to preserve model state errors through a POST-Redirect-GET cycle, I used <strong>asgeo1</strong>'s answer posted here:</p>
  
  <p><a href="https://stackoverflow.com/questions/4642845/asp-net-mvc-how-to-preserve-modelstate-errors-across-redirecttoaction">ASP.NET MVC - How to Preserve ModelState Errors Across RedirectToAction?</a></p>
  
  <p>I thought this worked well, but discovered in my latest project (VS 2015) that temp data actually persists.</p>
  
  <p>Scenario: user enters a value into a text input in Search, submits a post and is redirected to another page, Index. Then they click a link back to Search.</p>
  
  <p>Search.cshtml:</p>
  
  <pre><code>@model Foo.Models.TestModel
  
  &lt;form method="post" action="@Url.Content("~/Home/Search")"&gt;
      @Html.TextBoxFor(o =&gt; o.TestString)
      &lt;input name="find" type="submit" value="Search" /&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>Index.cshtml:</p>
  
  <pre><code>&lt;a href="@Url.Content("~/Home/Search")"&gt;Search&lt;/a&gt;
  </code></pre>
  
  <p>Controller:</p>
  
  <pre><code>    [HttpGet]
      [RestoreModelStateFromTempData]
      public ActionResult Search(TestModel model)
      {
          //var modelState = TempData["ModelState"] as ModelStateDictionary;
          //if (modelState != null)
          //    throw new Exception("Temp Data should be empty.");
          return View(model);
      }
  
      [HttpPost]
      [SetTempDataModelState]
      public ActionResult Search(TestModel_Post model)
      {
          return RedirectToAction("Index", "Home", null);
      }
  
      [HttpGet]
      public ActionResult Index() { return View(); }
  </code></pre>
  
  <p>To my surprise, the temp data from the previous post is preserved, and the model state from that gets merged and the user sees the last value they entered. This is on a fresh navigation to that page - there should be no temp data here.</p>
  
  <p>A workaround is to clear the model state if it's valid. But this was quite a shock to me - I don't feel I understand TempData any more.</p>
  
  <p>What's going on here?</p>