title: How do I obtain an HtmlHelper<TModel> instance for a model in ASP.NET MVC?
body: <p>Let's say I have an Index view. The model I pass in is actually a collection of models, so the <code>Html</code> property is of type <code>HtmlHelper&lt;List&lt;MyModel&gt;&gt;</code>. If I want to call extension methods (e.g., <code>Display()</code> or <code>DisplayFor()</code> on the individual items in the list, however, I think I need to obtain an <code>HtmlHelper&lt;MyModel&gt;</code>. But how?</p>
  
  <p>I tried using the <code>HtmlHelper&lt;TModel&gt;</code> constructor, which looks like this:</p>
  
  <pre><code>HtmlHelper&lt;TModel&gt;(ViewContext, IViewDataContainer)
  </code></pre>
  
  <p>But I'm not having any luck with that. I don't know how to obtain the <code>IViewDataContainer</code> for the item, and the documentation on these things is very sparse.</p>
  
  <p>A lot of magic apparently happens when I do...</p>
  
  <pre><code>return View(List&lt;MyModel&gt;);
  </code></pre>
  
  <p>...in my controller.</p>
  
  <p>How do I recreate that magic on individual items in a list/collection?</p>
  
  <p><strong>Update</strong></p>
  
  <p>Here is a code snippet to show what I'm trying to accomplish:</p>
  
  <pre><code>        foreach(var item in items)
          {
              var helper = new HtmlHelper&lt;ProjName.MyModel&gt;(ViewContext, ????);
  %&gt;
              &lt;tr&gt;
  &lt;%
                  foreach(var property in properties)
                  {
  %&gt;
                      &lt;td&gt;
                          &lt;%=  helper.Display(property.DisplayName) %&gt;
                      &lt;/td&gt;
  &lt;%          
                  }
  %&gt;
              &lt;/tr&gt;
  &lt;%
          }
  </code></pre>
  
  <p>Basically, I want to populate the cells of a table using the items in the collection. I just need help setting the <code>helper</code> variable.</p>