title: Nested BeginCollectionItem
body: <p>I'm using Steve Sanderson's BeginCollectionItem approach to add dynamic content. Everything works fine when I'm doing it on the first level. However, when try to implement a nested collection meaning a BeginCollectionItem in another BeginCollectionItem, it doesn't seem to work.</p>
  
  <p>My models are as follows:</p>
  
  <pre><code>public class Order
  {
  
          [Key]
          [HiddenInput]
          public int id { get; set; }
  
          [Display(Name = "Order number")]
          public string number { get; set; }
  
          ...
  
          [Display(Name = "Payment method")]
          public List&lt;PaymentMethod&gt; payment_methods { get; set; }
  
          ...
  }
  
  public class PaymentMethod
  {
          public MethodOfPayment method { get; set; }
          public CC cc { get; set; }
          public CASH cash { get; set; }
          public TT tt { get; set; }
  }
  
  public class TT
  {
          [Key]
          public int id { get; set; }
  
          [Required(ErrorMessage = "{0} is required.")]
          [Display(Name = "Total amount")]
          public double? total_value { get; set; }
  
          ...
  
          [Display(Name = "Transfers")]
          public List&lt;Transfer&gt; transfers { get; set; }
  }
  
  public class Transfer
  {
          [Key]
          public int id { get; set; }
  
          [Display(Name = "Payment")]
          public int payment_id { get; set; }
  
          [Required(ErrorMessage = "{0} is required.")]
          [Display(Name = "SWIFT")]
          public string swift { get; set; }
  
          [Required(ErrorMessage = "{0} is required.")]
          [Display(Name = "Amount transferred")]
          public double? transfer_amount { get; set; }
  
          [Required(ErrorMessage = "{0} is required.")]
          [Display(Name = "Date transferred")]
          public DateTime transfer_date { get; set; }
  
          ...
  }
  </code></pre>
  
  <p>Now what i have is an Order which could have several payment methods, and if one of the payment methods is a TT (telex transfer) it could have several transfers involved.
  Implementing several payment methods in one Order as a collection works, but when I try to implement several transfers within a TT, nothing of these transfers gets passed to the controller.</p>
  
  <p>Here's what my view looks like:</p>
  
  <pre><code>@model prj.Models.Model.Order
  
  @using (Html.BeginForm("Create")){
  @Html.ValidationSummary(true, "Creation was unsuccessful. Please correct the errors and try again.")
  
  ...
  
  @Html.TextBoxFor(m =&gt; m.number, new { id = "txtnumber" })
  
  ...
  
  
  &lt;div id="editorPaymentRows"&gt;
      @foreach (var payment in Model.payment_methods)
      {
          @Html.Partial("_NewPayment", payment)
      }
  &lt;/div&gt;
  
  }
  </code></pre>
  
  <p>In the _NewPayment partial:</p>
  
  <pre><code>@using prj.Helpers 
  @model prj.Models.Model.PaymentMethod
  
  &lt;div class="editPaymentRow"&gt;
  
  @using (Html.BeginCollectionItem("payment_methods"))
  {
  ...
  
  &lt;div class="editor-label"&gt;
      @Html.LabelFor(m =&gt; m.tt.total_value)&lt;req&gt;*&lt;/req&gt;      
  &lt;/div&gt;
  
  &lt;div class="editor-field"&gt;
      @Html.TextBoxFor(m =&gt; m.tt.total_value)
  &lt;/div&gt;
  
  ...
  
  
  &lt;div id="editorTransferRows"&gt;
     @if (Model.tt != null)
  {
      foreach (var transfer in Model.tt.transfers)
      {
           @Html.Partial("_NewTransfer", transfer)
      }
  }
  ...
  &lt;/div&gt;
  
  
  
  }
  
  &lt;/div&gt;
  </code></pre>
  
  <p>and finally in the _NewTransfer partial:</p>
  
  <pre><code>@using prj.Helpers 
  @model prj.Models.Model.Transfer
  ...
  
  &lt;div class="editTransferRow"&gt;
  //using (Html.BeginCollectionItem("transfers"))
  @using (Html.BeginCollectionItem("tt.transfers"))
  {
  ...
  
  &lt;div class="editor-label"&gt;
      @Html.LabelFor(m =&gt; m.swift)&lt;req&gt;*&lt;/req&gt;      
  &lt;/div&gt;
  
  &lt;div class="editor-field"&gt;
      @Html.TextBoxFor(m =&gt; m.swift, new { @class = "t_swift" })
  &lt;/div&gt;
  
  ...
  
  &lt;div class="editor-label"&gt;
      @Html.LabelFor(m =&gt; m.transfer_amount)&lt;req&gt;*&lt;/req&gt;      
  &lt;/div&gt;
  
  &lt;div class="editor-field"&gt;
      @Html.TextBoxFor(m =&gt; m.transfer_amount, new { @class = "t_transfer_amount" })
  &lt;/div&gt;
  
  ...
  }
  
  &lt;/div&gt;
  </code></pre>
  
  <p>So everything works, except in the controller the List transfers which is in TT property of the PaymentMethods is always null. It's not being passed to the controller properly. Is there something i'm missing?</p>
  
  <p>Does nested BeginCollectionItem not work? is there an extra step I must do?
  Please shed some light.
  Thanks</p>
  
  <hr>
  
  <p>I figured it out using Joe Stevens' method shown at the following link:</p>
  
  <p><a href="http://www.joe-stevens.com/2011/06/06/editing-and-binding-nested-lists-with-asp-net-mvc-2/" rel="noreferrer">http://www.joe-stevens.com/2011/06/06/editing-and-binding-nested-lists-with-asp-net-mvc-2/</a></p>
  
  <p>Cheers</p>