title: Asp.Net MVC EditorFor Array with template
body: <p>I have a model of ClassA that has a property that is an array of ClassB.</p>
  
  <pre><code>public class ClassA
  {
      public string ClassAProperty1 { get; set; }
      public string ClassAProperty2 { get; set; }
      public ClassB[] MySubCollection { get; set; }
  }
  
  public class ClassB
  {
      public string Prop1 { get; set; }
      public string Prop2 { get; set; }
  }
  </code></pre>
  
  <p>I'd like to edit my instances of ClassB in a table. I've created an EditorTemplate for ClassB that creates a table row.</p>
  
  <pre><code>    @model ClassB
      &lt;tr&gt;
          &lt;td&gt;@Html.TextBoxFor(m =&gt; m.Prop1)&lt;/td&gt;
          &lt;td&gt;@Html.TextBoxFor(m =&gt; m.Prop2)&lt;/td&gt;
      &lt;/tr&gt;
  </code></pre>
  
  <p>This works great on the edit view for ClassA since MVC does all the field indexing magic itself:</p>
  
  <pre><code>@Html.TextBoxFor(m =&gt; m.ClassAProperty1)
  @Html.TextBoxFor(m =&gt; m.ClassAProperty2)
  
  &lt;table&gt;
      &lt;tr&gt;
          &lt;th&gt;Col&lt;/th&gt;
          &lt;th&gt;Col&lt;/th&gt;
      &lt;/tr&gt;
      @Html.EditorFor(m =&gt; m.MySubCollection)
  &lt;/table&gt;
  </code></pre>
  
  <p>However, I'd actually like to create an editor template for the array that includes the table tag like this:</p>
  
  <pre><code>@model ClassB[]
  &lt;table&gt;
      &lt;tr&gt;
          &lt;th&gt;Col&lt;/th&gt;
          &lt;th&gt;Col&lt;/th&gt;
      &lt;/tr&gt;
     @foreach(var item in Model)
     {
         @Html.EditorFor(m =&gt; item)
     }
  &lt;/table&gt;
  </code></pre>
  
  <p>So I can simply do:</p>
  
  <pre><code>@Html.TextBoxFor(m =&gt; m.ClassAProperty1)
  @Html.TextBoxFor(m =&gt; m.ClassAProperty2)
  @Html.EditorFor(m =&gt; m.MySubCollection)
  </code></pre>
  
  <p>However, the field indexing is not applied with this approach. Is there a way I can accomplish this without having to build the textbox names myself? Being a template, I don't know the property name at the time of use.</p>