title: MVC nested EditorTemplate with Html.BeginCollectionItem extension always returns an object with values set to '0' or 'null'
body: <p>I am trying to return a model which contains one or more sub-models which, in turn, can also contain a sub-model. The first layer returns succesfully, however, when I want to return the 3rd layer of sub-model, I get a 'default' instance of that model without the actually filled in variables. So, the model returned contains a sub-model and the sub-model contains another sub-model, but that last sub-model's values are set to '0' and 'null'.</p>
  
  <p>I am using the Html.BeginItemCollection extension methods, but I am unsure if I am using them in the correct way at layer 3. If someone would please take a look at this and help me out?</p>
  
  <p><strong>Main model page (layer 1)</strong></p>
  
  <pre><code>@using Website.Models
  @model CreateAgendaBindingModel
  @using (Html.BeginForm(null, null, FormMethod.Post, new { id = "myForm" }))
  {
      &lt;div class="form-horizontal"&gt;   
      for (int i = 1; i &lt; 16; i++)
      {
          &lt;div id='CreateVoedingDiv_@i'&gt;
                @Html.EditorFor(x =&gt; x.VoedingCollection[i], "CreateVoedingTemplate")
          &lt;/div&gt;
      }
  }
  </code></pre>
  
  <p><strong>Main model class (layer 1)</strong></p>
  
  <pre><code>public class CreateAgendaBindingModel
  {
      public int Id { get; set; }
      public List&lt;CreateVoedingBindingModel&gt; VoedingCollection { get; set; }
  }
  </code></pre>
  
  <p><strong>Sub-model page (layer 2)</strong></p>
  
  <pre><code>@using HtmlHelpers.BeginCollectionItem;
  @using Website.Models
  
  @model CreateVoedingBindingModel
  
  @using (Html.BeginCollectionItem("VoedingCollection"))
  {
      &lt;div class="form-group" id=@customVoedingId&gt;
              @Html.EditorFor(x =&gt; x.CustomVoeding[0], "CreateCustomVoedingTemplate")
      &lt;/div&gt;
  }
  </code></pre>
  
  <p><strong>Sub-model class (layer 2)</strong></p>
  
  <pre><code>public class CreateVoedingBindingModel
  {
      public int Id { get; set; }
      public List&lt;customvoeding&gt; CustomVoeding { get; set; }
  }
  </code></pre>
  
  <p><strong>Sub-model of sub-model page (layer 3)</strong></p>
  
  <pre><code>@using HtmlHelpers.BeginCollectionItem;
  @model FoodtrackerModel.customvoeding
  
  @using (Html.BeginCollectionItem(ViewData.TemplateInfo.HtmlFieldPrefix + ".CustomVoeding"))
  {
      &lt;div class="form-group"&gt;
          @Html.Label("Opmerking (optioneel)", htmlAttributes: new { @class = "control-label col-md-2" })
          &lt;div class="col-md-10"&gt;
              @Html.EditorFor(model =&gt; model.customVoedingOpmerking, new { htmlAttributes = new { @class = "form-control" } })                   
          &lt;/div&gt;
      &lt;/div&gt;
  }
  </code></pre>
  
  <p>The sub-model of sub-model class is a partial class which is integrated with Entity Framework.</p>
  
  <p><strong>Sub-model of sub-model class (layer 3)</strong></p>
  
  <pre><code>public partial class customvoeding
  {
      public static List&lt;customvoeding&gt; GetAllCustomvoeding()
      {
          using (foodtrackerEntities1 db = new foodtrackerEntities1())
          {
              db.Configuration.LazyLoadingEnabled = false;
              return db.customvoeding.ToList();
          }
      }
  }
  </code></pre>
  
  <p>So to clarify, layer 1 and 2 are returned with all variables filled in. Layer 3 is returned but no variables are filled in.</p>