title: MVC 3 - Html.EditorFor seems to cache old values after $.ajax call
body: <p>This is a follow on from the following question:</p>
  
  <p><a href="https://stackoverflow.com/questions/7404334/mvc-3-ajax-response-seems-to-be-caching-output-from-partial-view">MVC 3 + $.ajax - response seems to be caching output from partial view</a></p>
  
  <p>There is a detailed description of the problem over there.  However, I have now managed to narrow down the problem, that seems to be with the Html.EditorFor helpers, hence the new question.</p>
  
  <p>The issue:</p>
  
  <p>I post data to the server using $.ajax, then return the html of the partial view that holds the input controls.  The problem is that, despite passing a newly created object to the Partial Views model, the various @Html.EditorFor and @Html.DropDownListFor helpers return the OLD DATA!.</p>
  
  <p>I can prove that the model has correctly passed in a new object to the helpers, by printing the value out beside the Html helper.  Ie:</p>
  
  <pre><code>@Html.EditorFor(model =&gt; model.Transaction.TransactionDate) 
  @Model.Transaction.TransactionDate.ToString()
  </code></pre>
  
  <p>As the following image shows, the @Html.EditorFor is returning the wrong data:</p>
  
  <p><img src="https://i.stack.imgur.com/L53qi.jpg" alt="Cached response..."></p>
  
  <p>[Note that the value beside the Comentario text box is a date time, because I was testing replacing the default values with a value that would change with each post, ie, a DateTime.]</p>
  
  <p>If I replace the @Html.EditorFor for TransactionDate with a plain old @Html.TextBox():</p>
  
  <pre><code>@Html.TextBox("Transaction_TransactionDate", Model.Transaction.TransactionDate)
  </code></pre>
  
  <p>Then it renders the correct TransactionDate value for a new Transaction object, ie, DateTime.MinValue (01/01/0001...).</p>
  
  <p>Therefore...</p>
  
  <p>The problem is with the @Html.EditorFor helpers.  The problem also happens with TextBoxFor and DropDownListFor.</p>
  
  <p><strong>The problem being that these helpers seem to cache the old value.</strong></p>
  
  <p>What am I doing wrong??!</p>
  
  <h2>EDIT:</h2>
  
  <p>I have just tried debugging in the custom Editor template for dates, and in there, ViewData.TemplateInfo.FormattedModelValue shows the correct value, ie, "01/01/0001".  However, once it gets to Fiddler, the response is showing the old date, eg, "01/09/2011" in the image above.</p>
  
  <p>As a result, I just think that there is some caching going on here, but I have none set up, so nothing makes any sense.</p>