title: ASP.NET MVC - Controller receives the list incorret from view using Html.BeginForm()
body: <p>I want to get multiple instances of my model objects sent to the controller as a list but for some reason, the count of the list is always 1 and the value of the object is always 0 so nothing is actually posted when submit is pressed.</p>
  <p>This is my View:</p>
  <pre><code>@model List&lt;MVCModel.Models.Student&gt;
  
   &lt;b&gt;Items&lt;/b&gt;    @ViewBag.Items &lt;br /&gt;
   &lt;b&gt;Value&lt;/b&gt;    @ViewBag.Value &lt;br /&gt;
    
  @using (Html.BeginForm(&quot;Form&quot;, &quot;Home&quot;, FormMethod.Post))
  {
  &lt;table&gt;
      &lt;tbody id=&quot;GenaratorList&quot;&gt;
          &lt;tr&gt;
            @{
              int counter = 0;
              &lt;td&gt;Enter Name: &lt;/td&gt;
              &lt;td&gt;@Html.TextBoxFor(m =&gt; m[counter].Name, new {id = &quot;Name&quot;})&lt;/td&gt;
              &lt;td&gt;Enter Age: &lt;/td&gt;
              &lt;td&gt;@Html.TextBoxFor(m =&gt; m[counter].Age, new {id = &quot;Age&quot;})&lt;/td&gt;
              &lt;td&gt;&lt;input type=&quot;button&quot; value=&quot;Add&quot; onclick=&quot;addGenarator()&quot; /&gt;&lt;/td&gt;
          &lt;/tr&gt;
          counter++;
          }
       &lt;tbody&gt;
  &lt;/table&gt;
  &lt;input type=&quot;submit&quot; value=&quot;Submit Form&quot;/&gt;
  }
  
  &lt;script&gt;
      count = 0;
      function addGenarator() {
          var Name = $('#Name').val();
          var Age = $('#Age').val();
          var Student = &quot;studentModels[&quot; + count + &quot;]&quot;;
          $('#GenaratorList').append('&lt;tr&gt;&lt;td&gt;&lt;input id=&quot;' + Student + '.Name&quot; Name=&quot;' + Student + '.Name&quot; type=&quot;text&quot; class=&quot;form-control&quot; readonly value=&quot;' + Name + '&quot;&gt;&lt;/td&gt;&lt;td&gt;&lt;input id=&quot;' + Student + '.Age&quot; Age=&quot;' + Student + '.Age&quot; type=&quot;text&quot; class=&quot;form-control&quot; readonly value=&quot;' + Age + '&quot;&gt;&lt;/td&gt;&lt;/tr&gt;');
          $('#Name,#Age').val('');
          count++;
      }
  &lt;/script&gt;
  </code></pre>
  <p>This is my Controller:</p>
  <pre class="lang-cs prettyprint-override"><code>[HttpPost]
  public ActionResult Form(List&lt;Student&gt; s)
  {
      ViewBag.Items = s.Count; // ALWAYS RETURNS 1
      ViewBad.Value = s[0].Age // TEST VALUE OF FIRST ITEM RETURNS 0
      return View(&quot;Index&quot;);
  }
  </code></pre>
  <p>This is my model:</p>
  <pre class="lang-cs prettyprint-override"><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Web;
  
  namespace MVCModel.Models
  {
      public class Student
      {
          public string Name { get; set; }
          public int Age { get; set; }
      }
  }
  </code></pre>