title: Binding List of Lists in MVC 2.0
body: <p>I need to handle a <code>List&lt;List&lt;T&gt;&gt;</code> in a form and couldn't find how to proceed with old version of MVC and .NET.</p>
  
  <p>I did try the following:</p>
  
  <p>Model:</p>
  
  <pre><code>public class MyModel
  {
      public List&lt;List&lt;Item&gt;&gt; ListA { get; set; }
  }
  
  public class Item
  {
      public string Name { get; set; }
      public string Spec { get; set; }
      public string Type { get; set; }
      public string Field1 { get; set; }
      public string Field2 { get; set; }
      public string Field3 { get; set; }
      public string Field4 { get; set; }
      public string Field5 { get; set; }
  }
  </code></pre>
  
  <p>View:</p>
  
  <pre><code>&lt;%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl&lt;MyModel&gt;" %&gt;
  
  &lt;% for(int i = 0; i &lt; Model.ListA.Count; i++) { %&gt;
      &lt;fieldset&gt;
          &lt;div&gt;
              &lt;input disabled="disabled" value="Name" /&gt;
              &lt;input disabled="disabled" value="Spec" /&gt;
              &lt;input disabled="disabled" value="Type" /&gt;
              &lt;input disabled="disabled" value="Field 1" /&gt;
              &lt;input disabled="disabled" value="Field 2" /&gt;
              &lt;input disabled="disabled" value="Field 3" /&gt;
              &lt;input disabled="disabled" value="Field 4" /&gt;
              &lt;input disabled="disabled" value="Field 5" /&gt;
          &lt;/div&gt;
          &lt;% for(int j = 0; j &lt; Model.ListA[i].Count; j++) { %&gt;
              &lt;div&gt;
                  &lt;%= Html.EditorFor(m =&gt; m.ListA[i][j].Name)%&gt;
                  &lt;%= Html.EditorFor(m =&gt; m.ListA[i][j].Spec)%&gt;
                  &lt;%= Html.EditorFor(m =&gt; m.ListA[i][j].Type)%&gt;
                  &lt;%= Html.EditorFor(m =&gt; m.ListA[i][j].Field1)%&gt;
                  &lt;%= Html.EditorFor(m =&gt; m.ListA[i][j].Field2)%&gt;
                  &lt;%= Html.EditorFor(m =&gt; m.ListA[i][j].Field3)%&gt;
                  &lt;%= Html.EditorFor(m =&gt; m.ListA[i][j].Field4)%&gt;
                  &lt;%= Html.EditorFor(m =&gt; m.ListA[i][j].Field5)%&gt;
              &lt;/div&gt;
          &lt;% } %&gt;
      &lt;/div&gt;
  &lt;% } %&gt;
  </code></pre>
  
  <p>Controller:</p>
  
  <pre><code>[HttpGet]
  public ActionResult MyAction(int Id)
  {
      // MyModel modObj = MyService.GetModelById(Id);
      MyModel modObj = new MyModel
      {
          ListA = new List&lt;List&lt;Item&gt;&gt;
          {
              new List&lt;Item&gt;
              {
                  new Item { Name = "0 - 0" },
                  new Item { Name = "0 - 1" },
                  new Item { Name = "0 - 2" }
              },
              new List&lt;Item&gt;
              {
                  new Item { Name = "1 - 0" },
                  new Item { Name = "1 - 1" },
                  new Item { Name = "1 - 2" }
              }
          }
      }
  
      return View(modObj);
  }
  
  [HttpPost]
  public ActionResult MyAction(MyModel model)
  {
      // anything
      return null;
  }
  </code></pre>
  
  <p><strong>My problem is that currently, even if I can correctly see the editors for every item</strong> (here the two lists of three items), <strong>when I post it back, I only see the first list of three items in the controller.</strong></p>
  
  <p>I also tried to change my model to:</p>
  
  <pre><code>public class MyModel
  {
     public List&lt;ItemList&gt; ListA { get; set; }
  }
  
  public class ItemList
  {
      public string PropId { get; set; }
      public List&lt;Item&gt; ListB { get; set; }
  }
  
  public class Item
  {
      public string Name { get; set; }
      public string Spec { get; set; }
      public string Type { get; set; }
      public string Field1 { get; set; }
      public string Field2 { get; set; }
      public string Field3 { get; set; }
      public string Field4 { get; set; }
      public string Field5 { get; set; }
  }
  </code></pre>
  
  <p>and changed my View and Controller accordingly, but I still get the same result: <strong>the first List level only contains one List when I post it back</strong> - I only get <code>"0 - 0"</code>, <code>"0 - 1"</code> &amp; <code>"0 - 2"</code> when setting a breakpoint in the POST method of the controller.</p>
  
  <p>I'm out of idea here.</p>
  
  <p><strong>Edit:</strong> To answer Jonny's question, this is how it looks like with <code>List&lt;ItemList&gt;</code>:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;fieldset&gt;
      &lt;div&gt;
          &lt;input disabled="disabled" value="Name" /&gt;
          &lt;input disabled="disabled" value="Spec" /&gt;
          &lt;input disabled="disabled" value="Type" /&gt;
          &lt;input disabled="disabled" value="Field 1" /&gt;
          &lt;input disabled="disabled" value="Field 2" /&gt;
          &lt;input disabled="disabled" value="Field 3" /&gt;
          &lt;input disabled="disabled" value="Field 4" /&gt;
          &lt;input disabled="disabled" value="Field 5" /&gt;
      &lt;/div&gt;
      &lt;div&gt;
          &lt;input name="ListA[0].ListB[0].Name" id="ListA_0__ListB_0__Name" type="text" value="0 - 0"&gt;&lt;/input&gt;
          &lt;input name="ListA[0].ListB[0].Spec" id="ListA_0__ListB_0__Spec" type="text"&gt;&lt;/input&gt;
          &lt;input name="ListA[0].ListB[0].Type" id="ListA_0__ListB_0__Type" type="text"&gt;&lt;/input&gt;
          &lt;input name="ListA[0].ListB[0].Field1" id="ListA_0__ListB_0__Field1" type="text"&gt;&lt;/input&gt;
          &lt;input name="ListA[0].ListB[0].Field2" id="ListA_0__ListB_0__Field2" type="text"&gt;&lt;/input&gt;
          &lt;input name="ListA[0].ListB[0].Field3" id="ListA_0__ListB_0__Field3" type="text"&gt;&lt;/input&gt;
          &lt;input name="ListA[0].ListB[0].Field4" id="ListA_0__ListB_0__Field4" type="text"&gt;&lt;/input&gt;
          &lt;input name="ListA[0].ListB[0].Field5" id="ListA_0__ListB_0__Field5" type="text"&gt;&lt;/input&gt;
      &lt;/div&gt;
      &lt;div&gt;
          &lt;input name="ListA[0].ListB[1].Name" id="ListA_0__ListB_1__Name" type="text" value="0 - 1"&gt;&lt;/input&gt;
          &lt;input name="ListA[0].ListB[1].Spec" id="ListA_0__ListB_1__Spec" type="text"&gt;&lt;/input&gt;
          &lt;input name="ListA[0].ListB[1].Type" id="ListA_0__ListB_1__Type" type="text"&gt;&lt;/input&gt;
          &lt;input name="ListA[0].ListB[1].Field1" id="ListA_0__ListB_1__Field1" type="text"&gt;&lt;/input&gt;
          &lt;input name="ListA[0].ListB[1].Field2" id="ListA_0__ListB_1__Field2" type="text"&gt;&lt;/input&gt;
          &lt;input name="ListA[0].ListB[1].Field3" id="ListA_0__ListB_1__Field3" type="text"&gt;&lt;/input&gt;
          &lt;input name="ListA[0].ListB[1].Field4" id="ListA_0__ListB_1__Field4" type="text"&gt;&lt;/input&gt;
          &lt;input name="ListA[0].ListB[1].Field5" id="ListA_0__ListB_1__Field5" type="text"&gt;&lt;/input&gt;
      &lt;/div&gt;
      &lt;div&gt;
          &lt;input name="ListA[0].ListB[2].Name" id="ListA_0__ListB_2__Name" type="text" value="0 - 2"&gt;&lt;/input&gt;
          &lt;input name="ListA[0].ListB[2].Spec" id="ListA_0__ListB_2__Spec" type="text"&gt;&lt;/input&gt;
          &lt;input name="ListA[0].ListB[2].Type" id="ListA_0__ListB_2__Type" type="text"&gt;&lt;/input&gt;
          &lt;input name="ListA[0].ListB[2].Field1" id="ListA_0__ListB_2__Field1" type="text"&gt;&lt;/input&gt;
          &lt;input name="ListA[0].ListB[2].Field2" id="ListA_0__ListB_2__Field2" type="text"&gt;&lt;/input&gt;
          &lt;input name="ListA[0].ListB[2].Field3" id="ListA_0__ListB_2__Field3" type="text"&gt;&lt;/input&gt;
          &lt;input name="ListA[0].ListB[2].Field4" id="ListA_0__ListB_2__Field4" type="text"&gt;&lt;/input&gt;
          &lt;input name="ListA[0].ListB[2].Field5" id="ListA_0__ListB_2__Field5" type="text"&gt;&lt;/input&gt;
      &lt;/div&gt;
  &lt;/fieldset&gt;
  &lt;fieldset&gt;
      &lt;div&gt;
          &lt;input disabled="disabled" value="Name" /&gt;
          &lt;input disabled="disabled" value="Spec" /&gt;
          &lt;input disabled="disabled" value="Type" /&gt;
          &lt;input disabled="disabled" value="Field 1" /&gt;
          &lt;input disabled="disabled" value="Field 2" /&gt;
          &lt;input disabled="disabled" value="Field 3" /&gt;
          &lt;input disabled="disabled" value="Field 4" /&gt;
          &lt;input disabled="disabled" value="Field 5" /&gt;
      &lt;/div&gt;
      &lt;div&gt;
          &lt;input name="ListA[1].ListB[0].Name" id="ListA_1__ListB_0__Name" type="text" value="1 - 0"&gt;&lt;/input&gt;
          &lt;input name="ListA[1].ListB[0].Spec" id="ListA_1__ListB_0__Spec" type="text"&gt;&lt;/input&gt;
          &lt;input name="ListA[1].ListB[0].Type" id="ListA_1__ListB_0__Type" type="text"&gt;&lt;/input&gt;
          &lt;input name="ListA[1].ListB[0].Field1" id="ListA_1__ListB_0__Field1" type="text"&gt;&lt;/input&gt;
          &lt;input name="ListA[1].ListB[0].Field2" id="ListA_1__ListB_0__Field2" type="text"&gt;&lt;/input&gt;
          &lt;input name="ListA[1].ListB[0].Field3" id="ListA_1__ListB_0__Field3" type="text"&gt;&lt;/input&gt;
          &lt;input name="ListA[1].ListB[0].Field4" id="ListA_1__ListB_0__Field4" type="text"&gt;&lt;/input&gt;
          &lt;input name="ListA[1].ListB[0].Field5" id="ListA_1__ListB_0__Field5" type="text"&gt;&lt;/input&gt;
      &lt;/div&gt;
      &lt;div&gt;
          &lt;input name="ListA[1].ListB[1].Name" id="ListA_1__ListB_1__Name" type="text" value="1 - 1"&gt;&lt;/input&gt;
          &lt;input name="ListA[1].ListB[1].Spec" id="ListA_1__ListB_1__Spec" type="text"&gt;&lt;/input&gt;
          &lt;input name="ListA[1].ListB[1].Type" id="ListA_1__ListB_1__Type" type="text"&gt;&lt;/input&gt;
          &lt;input name="ListA[1].ListB[1].Field1" id="ListA_1__ListB_1__Field1" type="text"&gt;&lt;/input&gt;
          &lt;input name="ListA[1].ListB[1].Field2" id="ListA_1__ListB_1__Field2" type="text"&gt;&lt;/input&gt;
          &lt;input name="ListA[1].ListB[1].Field3" id="ListA_1__ListB_1__Field3" type="text"&gt;&lt;/input&gt;
          &lt;input name="ListA[1].ListB[1].Field4" id="ListA_1__ListB_1__Field4" type="text"&gt;&lt;/input&gt;
          &lt;input name="ListA[1].ListB[1].Field5" id="ListA_1__ListB_1__Field5" type="text"&gt;&lt;/input&gt;
      &lt;/div&gt;
      &lt;div&gt;
          &lt;input name="ListA[1].ListB[2].Name" id="ListA_1__ListB_2__Name" type="text" value="1 - 2"&gt;&lt;/input&gt;
          &lt;input name="ListA[1].ListB[2].Spec" id="ListA_1__ListB_2__Spec" type="text"&gt;&lt;/input&gt;
          &lt;input name="ListA[1].ListB[2].Type" id="ListA_1__ListB_2__Type" type="text"&gt;&lt;/input&gt;
          &lt;input name="ListA[1].ListB[2].Field1" id="ListA_1__ListB_2__Field1" type="text"&gt;&lt;/input&gt;
          &lt;input name="ListA[1].ListB[2].Field2" id="ListA_1__ListB_2__Field2" type="text"&gt;&lt;/input&gt;
          &lt;input name="ListA[1].ListB[2].Field3" id="ListA_1__ListB_2__Field3" type="text"&gt;&lt;/input&gt;
          &lt;input name="ListA[1].ListB[2].Field4" id="ListA_1__ListB_2__Field4" type="text"&gt;&lt;/input&gt;
          &lt;input name="ListA[1].ListB[2].Field5" id="ListA_1__ListB_2__Field5" type="text"&gt;&lt;/input&gt;
      &lt;/div&gt;
  &lt;/fieldset&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>and with <code>List&lt;List&lt;Item&gt;&gt;</code>:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;fieldset&gt;
      &lt;div&gt;
          &lt;input disabled="disabled" value="Name" /&gt;
          &lt;input disabled="disabled" value="Spec" /&gt;
          &lt;input disabled="disabled" value="Type" /&gt;
          &lt;input disabled="disabled" value="Field 1" /&gt;
          &lt;input disabled="disabled" value="Field 2" /&gt;
          &lt;input disabled="disabled" value="Field 3" /&gt;
          &lt;input disabled="disabled" value="Field 4" /&gt;
          &lt;input disabled="disabled" value="Field 5" /&gt;
      &lt;/div&gt;
      &lt;div&gt;
          &lt;input name="ListA[0][0].Name" id="ListA_0__0__Name" type="text" value="0 - 0"&gt;&lt;/input&gt;
          &lt;input name="ListA[0][0].Spec" id="ListA_0__0__Spec" type="text"&gt;&lt;/input&gt;
          &lt;input name="ListA[0][0].Type" id="ListA_0__0__Type" type="text"&gt;&lt;/input&gt;
          &lt;input name="ListA[0][0].Field1" id="ListA_0__0__Field1" type="text"&gt;&lt;/input&gt;
          &lt;input name="ListA[0][0].Field2" id="ListA_0__0__Field2" type="text"&gt;&lt;/input&gt;
          &lt;input name="ListA[0][0].Field3" id="ListA_0__0__Field3" type="text"&gt;&lt;/input&gt;
          &lt;input name="ListA[0][0].Field4" id="ListA_0__0__Field4" type="text"&gt;&lt;/input&gt;
          &lt;input name="ListA[0][0].Field5" id="ListA_0__0__Field5" type="text"&gt;&lt;/input&gt;
      &lt;/div&gt;
      &lt;div&gt;
          &lt;input name="ListA[0][1].Name" id="ListA_0__1__Name" type="text" value="0 - 1"&gt;&lt;/input&gt;
          &lt;input name="ListA[0][1].Spec" id="ListA_0__1__Spec" type="text"&gt;&lt;/input&gt;
          &lt;input name="ListA[0][1].Type" id="ListA_0__1__Type" type="text"&gt;&lt;/input&gt;
          &lt;input name="ListA[0][1].Field1" id="ListA_0__1__Field1" type="text"&gt;&lt;/input&gt;
          &lt;input name="ListA[0][1].Field2" id="ListA_0__1__Field2" type="text"&gt;&lt;/input&gt;
          &lt;input name="ListA[0][1].Field3" id="ListA_0__1__Field3" type="text"&gt;&lt;/input&gt;
          &lt;input name="ListA[0][1].Field4" id="ListA_0__1__Field4" type="text"&gt;&lt;/input&gt;
          &lt;input name="ListA[0][1].Field5" id="ListA_0__1__Field5" type="text"&gt;&lt;/input&gt;
      &lt;/div&gt;
      &lt;div&gt;
          &lt;input name="ListA[0][2].Name" id="ListA_0__2__Name" type="text" value="0 - 2"&gt;&lt;/input&gt;
          &lt;input name="ListA[0][2].Spec" id="ListA_0__2__Spec" type="text"&gt;&lt;/input&gt;
          &lt;input name="ListA[0][2].Type" id="ListA_0__2__Type" type="text"&gt;&lt;/input&gt;
          &lt;input name="ListA[0][2].Field1" id="ListA_0__2__Field1" type="text"&gt;&lt;/input&gt;
          &lt;input name="ListA[0][2].Field2" id="ListA_0__2__Field2" type="text"&gt;&lt;/input&gt;
          &lt;input name="ListA[0][2].Field3" id="ListA_0__2__Field3" type="text"&gt;&lt;/input&gt;
          &lt;input name="ListA[0][2].Field4" id="ListA_0__2__Field4" type="text"&gt;&lt;/input&gt;
          &lt;input name="ListA[0][2].Field5" id="ListA_0__2__Field5" type="text"&gt;&lt;/input&gt;
      &lt;/div&gt;
  &lt;/fieldset&gt;
  &lt;fieldset&gt;
      &lt;div&gt;
          &lt;input disabled="disabled" value="Name" /&gt;
          &lt;input disabled="disabled" value="Spec" /&gt;
          &lt;input disabled="disabled" value="Type" /&gt;
          &lt;input disabled="disabled" value="Field 1" /&gt;
          &lt;input disabled="disabled" value="Field 2" /&gt;
          &lt;input disabled="disabled" value="Field 3" /&gt;
          &lt;input disabled="disabled" value="Field 4" /&gt;
          &lt;input disabled="disabled" value="Field 5" /&gt;
      &lt;/div&gt;
      &lt;div&gt;
          &lt;input name="ListA[1][0].Name" id="ListA_1__0__Name" type="text" value="1 - 0"&gt;&lt;/input&gt;
          &lt;input name="ListA[1][0].Spec" id="ListA_1__0__Spec" type="text"&gt;&lt;/input&gt;
          &lt;input name="ListA[1][0].Type" id="ListA_1__0__Type" type="text"&gt;&lt;/input&gt;
          &lt;input name="ListA[1][0].Field1" id="ListA_1__0__Field1" type="text"&gt;&lt;/input&gt;
          &lt;input name="ListA[1][0].Field2" id="ListA_1__0__Field2" type="text"&gt;&lt;/input&gt;
          &lt;input name="ListA[1][0].Field3" id="ListA_1__0__Field3" type="text"&gt;&lt;/input&gt;
          &lt;input name="ListA[1][0].Field4" id="ListA_1__0__Field4" type="text"&gt;&lt;/input&gt;
          &lt;input name="ListA[1][0].Field5" id="ListA_1__0__Field5" type="text"&gt;&lt;/input&gt;
      &lt;/div&gt;
      &lt;div&gt;
          &lt;input name="ListA[1][1].Name" id="ListA_1__1__Name" type="text" value="1 - 1"&gt;&lt;/input&gt;
          &lt;input name="ListA[1][1].Spec" id="ListA_1__1__Spec" type="text"&gt;&lt;/input&gt;
          &lt;input name="ListA[1][1].Type" id="ListA_1__1__Type" type="text"&gt;&lt;/input&gt;
          &lt;input name="ListA[1][1].Field1" id="ListA_1__1__Field1" type="text"&gt;&lt;/input&gt;
          &lt;input name="ListA[1][1].Field2" id="ListA_1__1__Field2" type="text"&gt;&lt;/input&gt;
          &lt;input name="ListA[1][1].Field3" id="ListA_1__1__Field3" type="text"&gt;&lt;/input&gt;
          &lt;input name="ListA[1][1].Field4" id="ListA_1__1__Field4" type="text"&gt;&lt;/input&gt;
          &lt;input name="ListA[1][1].Field5" id="ListA_1__1__Field5" type="text"&gt;&lt;/input&gt;
      &lt;/div&gt;
      &lt;div&gt;
          &lt;input name="ListA[1][2].Name" id="ListA_1__2__Name" type="text" value="1 - 2"&gt;&lt;/input&gt;
          &lt;input name="ListA[1][2].Spec" id="ListA_1__2__Spec" type="text"&gt;&lt;/input&gt;
          &lt;input name="ListA[1][2].Type" id="ListA_1__2__Type" type="text"&gt;&lt;/input&gt;
          &lt;input name="ListA[1][2].Field1" id="ListA_1__2__Field1" type="text"&gt;&lt;/input&gt;
          &lt;input name="ListA[1][2].Field2" id="ListA_1__2__Field2" type="text"&gt;&lt;/input&gt;
          &lt;input name="ListA[1][2].Field3" id="ListA_1__2__Field3" type="text"&gt;&lt;/input&gt;
          &lt;input name="ListA[1][2].Field4" id="ListA_1__2__Field4" type="text"&gt;&lt;/input&gt;
          &lt;input name="ListA[1][2].Field5" id="ListA_1__2__Field5" type="text"&gt;&lt;/input&gt;
      &lt;/div&gt;
  &lt;/fieldset&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <hr>
  
  <h2>Edit 2</h2>
  
  <p>I finally managed to make it, rewriting the same code line by line...<br>
  So I have no idea why it didn't work before.</p>