title: Nested List of Lists with BeginCollectionItem
body: <p>I'm using BeginCollectionItem to add items to an inner list of lists.</p>
  
  <p>My question is very similar to the following: <a href="https://stackoverflow.com/questions/9575732/nested-begincollectionitem">Nested BeginCollectionItem</a>, however my the object that contains the list is also a list itself (so in the referenced example the tt is a List rather than just one instance of the object).</p>
  
  <p>My Models are:</p>
  
  <pre><code>public class WeeklyTimeSheetViewModel
  {
      public Guid WeeklyId { get; set; }
      public DateTime WeekCommencing { get; set; }
      public int WeekNumber { get; set; }
      public Employee Employee { get; set; }
  
      public List&lt;TimeSheetDayViewModel&gt; Days{ get; set; }
  
      public double HourlyRate { get; set; }
      public double OvernightRate { get; set; }
  
  }
  
  public class TimeSheetDayViewModel
  {
      public Guid DayId { get; set; }
      public DateTime Date { get; set; }
      public List&lt;TimeBookingViewModel&gt; Hours { get; set; }
      public bool Overnight { get; set; }
  }
  
  public class TimeBookingViewModel
  {
      public Guid BookingId { get; set; }
      public string TimeRef { get; set; }
      public string TimeDescription { get; set; }
  
      public double NormalHours { get; set; }
      public double OvertimeHoursR1 { get; set; }
      public double OvertimeHoursR2 { get; set; }
  }
  </code></pre>
  
  <p>So in my view I have a form which represents a full week time sheet, so a list of days (public List Days) and then each day has a list of hours to be booked against it (public List Hours).</p>
  
  <p>My view looks like this:
  WeeklyTimeSheet.cshtml</p>
  
  <pre><code>@model Models.WeeklyTimeSheetViewModel
  
  &lt;div style="margin: 5px;"&gt;
      &lt;h1&gt;Time Sheet&lt;/h1&gt;
  
      @using (Html.BeginForm(FormMethod.Post))
      {  
          ...
          @Html.EditorFor(model =&gt; model.Days)  
          ...  
      }
  &lt;/div&gt;
  </code></pre>
  
  <p>TimeSheetDayViewModel.cshtml (in editortemplates)</p>
  
  <pre><code>@using (Html.BeginCollectionItem("Days"))
  {
      &lt;table class="formtable"&gt;
  
          @Html.HiddenFor(model =&gt; model.DayId)
          @Html.HiddenFor(model =&gt; model.Date)
          &lt;thead&gt;
          &lt;tr&gt;
              &lt;th class="formtableheader" colspan="6"&gt;@Model.Date.DayOfWeek @Model.Date.ToLongDateString()&lt;/th&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td class="formtabletools formtableleft"&gt;Overnight: @Html.CheckBoxFor(model =&gt; model.Overnight)&lt;/td&gt;
              &lt;td class="formtabletools formtableright" colspan="5"&gt;
                  &lt;a href="javascript:void(0)" onclick="AddTimeBooking('@Model.Date.ToShortDateString()');"&gt;add&lt;/a&gt;
              &lt;/td&gt;
  
          &lt;/tr&gt;
          &lt;tr class="formtablecolumns"&gt;
              &lt;th&gt;Ref&lt;/th&gt;
              &lt;th&gt;Description&lt;/th&gt;
              &lt;th&gt;Hours&lt;/th&gt;
              &lt;th&gt;Overtime x1.5&lt;/th&gt;
              &lt;th&gt;Overtime x2.0&lt;/th&gt;
              &lt;th&gt;&lt;/th&gt;
          &lt;/tr&gt;
          &lt;/thead&gt;
          &lt;tbody id="@Model.Date.ToShortDateString()"&gt;
  
              @Html.EditorFor(model =&gt; model.Hours)
  
          &lt;/tbody&gt;
      &lt;/table&gt;
  }
  </code></pre>
  
  <p>TimeBookingViewModel.cshtml (editortemplates)</p>
  
  <pre><code>@model Models.TimeBookingViewModel
  @{
      var methodPrefix = ViewData.TemplateInfo.HtmlFieldPrefix;
  }
  @using (Html.BeginCollectionItem(methodPrefix + ".Hours"))
   {
       @Html.HiddenFor(model =&gt; model.BookingId)
       &lt;tr&gt;
           &lt;td&gt;@Html.TextBoxFor(model =&gt; model.TimeRef, new {@class = "short"})&lt;/td&gt;
           &lt;td&gt;@Html.TextBoxFor(model =&gt; model.TimeDescription, new {@class = "longer"})&lt;/td&gt;
           &lt;td&gt;@Html.TextBoxFor(model =&gt; model.NormalHours, new {@class = "tiny"})&lt;/td&gt;
           &lt;td&gt;@Html.TextBoxFor(model =&gt; model.OvertimeHoursR1, new {@class = "tiny"})&lt;/td&gt;
           &lt;td&gt;@Html.TextBoxFor(model =&gt; model.OvertimeHoursR2, new {@class = "tiny"})&lt;/td&gt;
  
           &lt;td&gt;&lt;a href="javascript:void(0)" onclick="DeleteTimeBooking(event)"&gt;delete&lt;/a&gt;&lt;/td&gt;
       &lt;/tr&gt;
   }
  </code></pre>
  
  <p>On the post back to the server TimeBookingViewModel objects are not populated. Any suggestions?</p>