title: How can I call DisplayFor from inside of a custom extension
body: <p>I am trying to write some <code>HtmlHelper</code> extension to clean up my views. I have a need to use <code>Html.DisplayFor()</code> to render my model. I write the following extension</p>
  
  <pre><code>public static MvcHtmlString MakeTableBodyTd(this HtmlHelper html, ModelMetadata metaData)
  {
      var td = new TagBuilder("td");
  
      if (metaData != null)
      {
          var cssClassName = metaData.AdditionalValues.GetValueOrDefault("TextAlignment", "left");
  
          td.AddCssClass(cssClassName);
  
          var t = html.DisplayFor(x =&gt; metaData.Model, metaData.DataTypeName, new { Metadata = metaData }).ToHtmlString();
  
          td.InnerHtml = t;
      }
  
      return new MvcHtmlString(td.ToString());
  }
  </code></pre>
  
  <p>However, this extension is giving me this error</p>
  
  <blockquote>
    <p>'HtmlHelper' does not contain a definition for 'DisplayFor' and no
    extension method 'DisplayFor(...)' accepting a first argument of type
    'HtmlHelper' could be found (are you missing a using directive or an
    assembly reference?</p>
  </blockquote>
  
  <p>I am able to use <code>@Html.DisplayFor(...)</code> in my views with no issues, but unable to use the in the extensions class.</p>
  
  <p>I have added a reference to the following libraries</p>
  
  <pre><code>using System.Web.Mvc;
  using System.Web.Mvc.Html;
  </code></pre>
  
  <p>But still giving me the error.</p>
  
  <p>The html has only the following methods available <code>html.Display()</code>, <code>html.DisplayForModel()</code>, <code>html.DisplayName()</code>, <code>html.DisplayNameForModel()</code> and <code>html.DisplayText()</code></p>
  
  <p>How can I use the <code>html.DisplayFor(...)</code> method inside my extension?</p>