title: ASP.Net MVC Editor template for dynamic view data / forms
body: <p>I am implementing a MVC3/Razor web application that retrieves some of its "fields" a user can edit from other services so the list of properties to edit in a view is completely dynamic and unknown at compile time.</p>
  
  <p>I wrote some partial-view and HTML-helpers that loop through the groups and properties retrieved from the other services. Now I am at the point where I have to build the  tags for the various property types and thought why not re-use the MVC editor template system for this? There is support for various data-types (eg. checkboxes etc.) and one even customize them with my custom templates.</p>
  
  <p>So far so good but how can I use <code>Html.EditorFor()</code> or <code>Html.Editor()</code> for custom data objects/properties? Meaning for building dynamic forms without static typed data as the view model.</p>
  
  <p>Here is a minimalistic sample of my HTML helper code:</p>
  
  <pre><code>public static MvcHtmlString GetField(this HtmlHelper helper, Field field)
  {
  ...
     return helper.EditorFor(field, m =&gt; m.Value);
  ...
  }
  </code></pre>
  
  <p>The property "field" is the field I got from the external services. It has a "Value" property of type object. I like to build the editor code for this property-type.</p>
  
  <p>As I understand the editor templates are built on the current view model. Can I pass another object as the model then the current view model (eg. in my above example "field")?</p>
  
  <p>Any help would be great!</p>
  
  <p>Cheers,
  Marc</p>