title: MVC3 Razor - TextBoxFor() values bound to a view model do not update correctly after returning from Post
body: <p>My view displays a series of rows in an html table. The rows are ordered by a rank order from the database. One of the columns in the html table is a textbox that will allow the user to modify this rank order.  There is an Update submit button at the bottom of the table which will allow the user to save this new order. The problem Im encountering is that the rank order is updated correctly to the database, but when the controller returns back to the view, all data is updated correctly on the screen but the values in the text box are not updated.</p>
  
  <pre><code>Order   |  Data     
  ================================================
  10      |  Item 1
  20      |  Item 2
  30      |  Item 3
  
  Lets say the user makes the following changes
  Order   |  Data
  ================================================
  50      |  Item 1
  20      |  Item 2
  10      |  Item 3
  
  Now User hits update and what is rendered is:
  
  Order   |  Data
  ================================================
  50      |  Item 3
  20      |  Item 2
  10      |  Item 1
  
  (Note data was sorted correctly but values of TextBoxFor did not update)
  </code></pre>
  
  <p>My View Code</p>
  
  <pre><code>@using (Html.BeginForm("UpdateRanks", "MyController")) {
      &lt;table cellpadding="0" cellspacing="0" width="100%"&gt;
      @for (int i = 0; i &lt; Model.DbSelections.Count; i++) {
         var item = Model.DbSelections[i];
         &lt;tr&gt;
          &lt;td&gt;
              @Html.TextBoxFor(m =&gt; m.DbSelections[i].Rank, new { @class = "NarrowTextBox" })
          &lt;/td&gt;
          &lt;td&gt;
              @Model.DbSelections[i].Rank (works!), @item.ItemName&lt;br /&gt;
          &lt;/td&gt;
         &lt;/tr&gt;
      }
      &lt;input type="submit" value="Update" name="updateaction"  class="StandardButton"/&gt;
  &lt;/table&gt;
  }
  </code></pre>
  
  <p>Controller code:</p>
  
  <pre><code>[HttpPost]
  [MultiButton(MatchFormKey = "updateaction", MatchFormValue = "Update")]
  public ActionResult UpdateRanks(MyViewModel model) {
  
      if (ModelState.IsValid) {
  
          MyRepository myRepo = new MyRepository();
          &lt;!-- saves updated ranks to database - it works --&gt;
          myRepo.UpdateAutoPicks(...);
  
          &lt;!-- after saved ranks above, now reload data including ranks from database --&gt;
          &lt;!-- debugging shows that data and ranks and ordering is correct-&gt;
          model.DbSelections = myRepo.GetItems();
  
          return View("Index", model);
  
  
      } else {
          &lt;!-- blah --&gt;
      }
  
      return View("Index", model);
  }
  </code></pre>