title: Asp.net mvc 2 templates without prefix
body: <p>Given following view model:</p>
  
  <pre><code>class DetailsViewModel
  {
     public HeaderViewModel Header {get;set;}
     public FooterViewModel Footer {get;set;}
  }
  </code></pre>
  
  <p>I'm using editor template for Header view model:</p>
  
  <pre><code>&lt;%: Html.EditorFor(x =&gt; x.Header) %&gt;
  </code></pre>
  
  <p>The editor template (EditorTemplates/HeaderViewModel.ascx)</p>
  
  <pre><code>&lt;%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl&lt;HeaderViewModel&gt;" %&gt;
  
  &lt;% ViewData.TemplateInfo.HtmlFieldPrefix = ""; %&gt;
  
  &lt;%: Html.EditorFor(x =&gt; x.Search) %&gt;
  </code></pre>
  
  <p>The result:</p>
  
  <pre><code>&lt;input type="text" value="" name="Search" id="Search" /&gt;
  </code></pre>
  
  <p>If I remove the line</p>
  
  <pre><code>&lt;% ViewData.TemplateInfo.HtmlFieldPrefix = ""; %&gt;
  </code></pre>
  
  <p>the result is:</p>
  
  <pre><code>&lt;input type="text" value="" name="Header.Search" id="Header_Search" /&gt;
  </code></pre>
  
  <p>Is there another way to achieve the same - render the names of the control without prefix?</p>
  
  <p>I was thinking about a helper:</p>
  
  <pre><code>public static MvcHtmlString EditorWithoutPrefix&lt;TModel, TValue&gt;(
    this HtmlHelper&lt;TModel&gt; html, TValue value)
  {
    var htmlHelper =... // create new HtmlHelper&lt;TValue&gt; and set it's model to be 'value' argument
  
    return htmlHelper.EditorForModel();
  }
  </code></pre>
  
  <p>and use it:</p>
  
  <pre><code>&lt;%: Html.EditorWithoutPrefix(Model.Header) %&gt;
  </code></pre>
  
  <p>but it is throwing exceptions.</p>
  
  <p>Or maybe you know another elegant way to render names without prefix?</p>