title: ASP.NET MVC 4 - for loop posts model collection properties but foreach does not
body: <p>Say I have the following models:</p>
  
  <pre><code>public class Person
  {
      public string Name { get; set; }
      public int Age { get; set; }
  }
  
  public class Town
  {
      public string Name { get; set; }
      public IEnumerable&lt;Person&gt; People { get; set; }
  }
  </code></pre>
  
  <p>Then, in my Razor view, I have this:</p>
  
  <pre><code>@model Town
  @using(Html.BeginForm())
  {
      &lt;table&gt;
          @foreach(var person in Model.People)
          {
              &lt;tr&gt;
                  &lt;td&gt;@Html.TextBoxFor(m =&gt; person.Name)&lt;/td&gt;
                  &lt;td&gt;@Html.TextBoxFor(m =&gt; person.Age)&lt;/td&gt;
              &lt;/tr&gt;
          }
      &lt;table&gt;
      &lt;input type="submit" /&gt;
  }
  </code></pre>
  
  <p>Then, I have an action for the POST, something like this:</p>
  
  <pre><code>[HttpPost]
  public ActionResult Index(Town theTown)
  {
      //....
  }
  </code></pre>
  
  <p>When I post, the <code>IEnumerable&lt;Person&gt;</code> does not come across.  If I look at it in Fiddler, the collection only posts once, and doesn't enumerate the collection, so I get:</p>
  
  <pre><code>People.Name = "whatever"
  People.Age = 99
  </code></pre>
  
  <p>However, if I change People to an <code>IList</code> and use a for loop instead of a foreach...</p>
  
  <pre><code>@for(var i = 0;i &lt; Model.People.Count;i++)
  {
      &lt;tr&gt;
          &lt;td&gt;@Html.TextBoxFor(m =&gt; Model.People[i].Name)&lt;/td&gt;
          &lt;td&gt;@Html.TextBoxFor(m =&gt; Model.People[i].Age)&lt;/td&gt;
      &lt;/tr&gt;
  }
  </code></pre>
  
  <p>It works.  Am I doing something wrong?  What am I missing?</p>