title: mvc4 get List index in editor template
body: <p>For my project i need to know the index of the list element in an editor template to give this to a delete button.</p>
  
  <p>For example i have a Model:</p>
  
  <pre><code>public class Model
  {
      public int ID { get; set; }
      public List&lt;TemplateModel&gt; Words { get; set; }
      public Model()
      {
      }
  }
  </code></pre>
  
  <p>a second Model with:</p>
  
  <pre><code>  public class TemplateModel
      {
          public int secondID { get; set; }
          public string word { get; set; }
          public TemplateModel()
          {
          }
      }
  </code></pre>
  
  <p>a View with:</p>
  
  <pre><code>@Html.EditorFor(m=&gt;m.Words)
  </code></pre>
  
  <p>and a template with:</p>
  
  <pre><code>    @model TemplateModel
  &lt;p&gt;@Html.TextBoxFor(m=&gt;m.word)&lt;/p&gt;
  &lt;p&gt;@Html.TextBoxFor(m=&gt;m.secondId)&lt;/p&gt;
  &lt;p&gt;&lt;input type="button" name="Index should be here"&gt;&lt;/p&gt;
  </code></pre>
  
  <p>is it possible to get the index from the list for the button? mvc automatically created names like <code>Words[index]</code> but how is it transmitting the index and is it possible to use him?</p>
  
  <p><strong>Update:</strong>
  I found a solution: 
  In the CiewContext is a method to build the names of the elements. So it is also able use this and attach an own string. So i implement this in the editor template:</p>
  
  <pre><code>&lt;input type="button" name="@ViewContext.ViewData.TemplateInfo.GetFullHtmlFieldName("Delete")"/&gt;
  </code></pre>
  
  <p>and in html it will look like</p>
  
  <pre><code>&lt;input type="button" name="Words[0].Delete"&gt;
  </code></pre>