title: ASP.NET MVC - Pass outer model to editor template
body: <p>I'm using custom editor templates for most of my forms, but while attempting to use them to render a custom object picker I've found no easy way to pass information about the containing context to the editor template.</p>
  
  <p>Specifically, my main form renders an edit for a domain object, and the editor template needs to render an AJAX picker which contains a list of objects which are dependent on the ID of the domain object. I'm passing the ID using the <code>additionalViewData</code> parameter currently, which I think is error prone and therefore quite ugly.</p>
  
  <p>My form contains code similar to the following:</p>
  
  <pre><code>@Html.EditorFor(model =&gt; model.CategoryId, new { id = model.id })
  </code></pre>
  
  <p>The editor template contains code like the following:</p>
  
  <pre><code>@{
  var domainObjectId = ViewData["id"] as int?;
  }
  </code></pre>
  
  <p>I'm using a custom <code>ModelMetadataProvider</code> to select the object picker editor template, and hope to use a similar technique to pass information about the containing model to the editor template, but that doesn't seem be possible.</p>
  
  <p>So, my questions are:</p>
  
  <ol>
  <li>Is there anyway to use a <code>ModelMetadataProvider</code> to pass information about the containing model to the editor template?</li>
  <li>If not, is there any neater/easier way to achieve what I'm attempting, aside from passing every piece of additional information via the weakly typed <code>additionalViewData</code> parameter?</li>
  </ol>
  
  <p>Thanks in advance!</p>