title: How do partial views access the index of an array that is located in the calling method?
body: <p>Trying to work out how MVC gets the index of an array within a partial view.</p>
  
  <p>I have the following code to demonstrate.</p>
  
  <pre><code>public class HomeController : Controller {
  
          public ActionResult Index() {
              return View(new[] { 
                  new Customer() { 
                      Orders = new [] { 
                          new Order() { Name="Shoes" },
                          new Order() { Name="Socks" },
                      }
                  }, 
                  new Customer() { 
                      Orders = new [] { 
                          new Order() { Name="Pants" },
                          new Order() { Name="Pantaloonies" },
                      }
                  }
              });
          }
      }
  </code></pre>
  
  <p>My Index.aspx view</p>
  
  <pre><code>&lt;asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server"&gt;
      &lt;%: Html.EditorForModel("_Customer") %&gt;
  &lt;/asp:Content&gt;
  </code></pre>
  
  <p>My _Customer.ascx</p>
  
  <pre><code>&lt;% using(Html.BeginForm("Index", "Home", FormMethod.Post)) { %&gt;
      &lt;% for (int i = 0; i &lt; Model.Length; i++) { %&gt;
         &lt;% for (int i2 = 0; i2 &lt; Model[i].Orders.Count(); i2++) { %&gt;
              &lt;%= Html.EditorFor(m =&gt; m[i].Orders[i2], "Orders")%&gt;    
         &lt;% } %&gt;
       &lt;% } %&gt;
       &lt;input type="submit" value="submit" /&gt;
   &lt;% } %&gt;
  </code></pre>
  
  <p>My Order.ascx</p>
  
  <pre><code>&lt;%= Html.LabelFor(m =&gt; m.Name) %&gt;
  &lt;%= Html.EditorFor(m =&gt; m.Name) %&gt;
  </code></pre>
  
  <p>The following HTML is rendered</p>
  
  <pre><code>&lt;form action="/" method="post"&gt;
  &lt;label for="[0]_Orders[0]_Name"&gt;Name&lt;/label&gt;
  &lt;input class="text-box single-line" name="[0].Orders[0].Name" type="text" value="Shoes" /&gt;
  &lt;label for="[0]_Orders[1]_Name"&gt;Name&lt;/label&gt;
  &lt;input class="text-box single-line" name="[0].Orders[1].Name" type="text" value="Socks" /&gt;
  &lt;label for="[1]_Orders[0]_Name"&gt;Name&lt;/label&gt;
  &lt;input class="text-box single-line" name="[1].Orders[0].Name" type="text" value="Pants" /&gt;
  &lt;label for="[1]_Orders[1]_Name"&gt;Name&lt;/label&gt;
  &lt;input class="text-box single-line" name="[1].Orders[1].Name" type="text" value="Pantaloonies" /&gt;&lt;input type="submit" value="submit" /&gt;
   &lt;/form&gt;
  </code></pre>
  
  <p>Where does Order.ascx get access to the index of the array from it's parent? I want to be able to set the index manually for one off ajax calls so I can fake the increment value.</p>