title: ASP.Net MVC - model with collection not populating on postback
body: <p>I have an ASP.Net MVC application with a model which is several layers deep containing a collection.  </p>
  
  <p>I believe that the view to create the objects is all set up correctly, but it just does not populate the collection within the model when I post the form to the server. </p>
  
  <p>I have a piece of data which is found in the class hierarchy thus: </p>
  
  <pre><code>person.PersonDetails.ContactInformation[0].Data;
  </code></pre>
  
  <p>This class structure is created by LinqToSQL, and ContactInformation is of type <code>EntitySet&lt;ContactData&gt;</code>. To create the view I pass the following: </p>
  
  <pre><code>return View(person);
  </code></pre>
  
  <p>and within the view I have a form which contains a single text box with a name associated to the above mentioned field: </p>
  
  <pre><code>&lt;%= Html.TextBox("person.PersonDetails.ContactInformation[0].Data")%&gt;
  </code></pre>
  
  <p>The post method within my controller is then as follows: </p>
  
  <pre><code>[AcceptVerbs(HttpVerbs.Post)]
  public ActionResult Create (Person person)
  {
    //Do stuff to validate and add to the database 
  }
  </code></pre>
  
  <p>It is at this point where I get lost as person.PersonDetails.ContactInformation.Count() ==0. So the ModelBinder has created a ContactInformation object but not populated it with the object which it should hold (i.e ContactData) at index 0.</p>
  
  <p>My question is two fold: 
  1. Have I taken the correct approach.. i.e. should this work?
  2. Any ideas as to why it might be failing to populate the ContactInformation object?</p>
  
  <p>Many thanks, 
  Richard</p>