title: ASP.NET MVC : Changing model's properties on postback
body: <p>I've been playing with ASP.NET MVC and ran into something I can't figure out.</p>
  
  <p>Suppose I have an object like this : </p>
  
  <pre><code>public class TestObject
  {
      public string Name { get; set; }
      public int Age { get; set; }
  }
  </code></pre>
  
  <p>And a view page (Create.aspx) like this : </p>
  
  <pre><code>&lt;form action="/Create" method="post"&gt;
      &lt;p&gt;
          &lt;%=Html.TextBox("Name") %&gt;
      &lt;/p&gt;
      &lt;p&gt;
          &lt;%=Html.TextBox("Age")%&gt;
      &lt;/p&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>And on my controller I have these actions : </p>
  
  <pre><code>[AcceptVerbs(HttpVerbs.Get)]
  public ActionResult Create()
  {
      return View(new TestObject { Name = "DefaultName", Age = 10 } );
  }
  
  [AcceptVerbs(HttpVerbs.Post)]
  public ActionResult Create(TestObject o)
  {
      o.Name = "ChangedNameToSomethingElse";
      o.Age = 15;
      return View(o);
  }
  </code></pre>
  
  <p>The <code>Html.TextBox()</code> method always genereates the textboxes with the default values, even after the postback, where the object is passed back with different properties on its values. Now, granted, I can't think of a real world example why I'd want to do such a thing but I still don't understand why I always end up having textboxes populated with the model's values that were set on the Create action with the <code>AcceptVerbs(HttpVerbs.Get)</code> attribute.</p>
  
  <p><strong>Note</strong> : I've tried <code>Html.TextBox("Name", Model.Name)</code> but the result is still the same. And I verified that the Create action with <code>AcceptVerbs(HttpVerbs.Post)</code> actually runs, by passing a value via ViewData to the View.
  Also, the udated value is displayed when I output the value with <code>&lt;%=Model.Name %&gt;</code> but again, not on the textbox.</p>
  
  <p>Is there something obvious I'm missing, or is there a reasoning behind this behaviour?</p>