title: Multiple Model Access in .NET Editor Templates
body: <p>I am trying to create a more "advanced" editor template for my MVC web application, but I am having a little bit of difficulty. Before I explain, let me show my source code.</p>
  
  <p>Here is the code in my view (using the template):</p>
  
  <pre><code>@Html.EditorFor(model =&gt; model.Height, "UnitTemplate", new { unitModel = Model.HeightUnit, unitType = Units.Distance })
  </code></pre>
  
  <p>Here is the template:</p>
  
  <pre><code>@{
      Layout = null;
  }
  @using MyProject.Models;
  
  @{
      var unitModel = this.ViewData["unitModel"];
      var unitType = this.ViewData["unitType"] as SelectList;
  }
  
  &lt;div class="data-group"&gt;
      &lt;div class="editor-label"&gt;
          @Html.LabelFor(model =&gt; model)
      &lt;/div&gt;
      &lt;div class="option1"&gt;
          @Html.TextBoxFor(model =&gt; model)
      &lt;/div&gt;
      &lt;div class="units"&gt;@Html.DropDownListFor(model =&gt; unitModel, unitType, new { @class = "unit" })&lt;/div&gt;
      &lt;div class="validation"&gt;
          &lt;div&gt;@Html.ValidationMessageFor(model =&gt; model)&lt;/div&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>As you can see, I have some value (in this case, Height) and I also have a unit type associated with that value (HeightUnit). I want to be able to GENERICALLY pass in the unit value associated with the model (since I am using this template in quite a number of places) as well as well as the type of unit (since this can also change). Ultimately, the goal is to allow the user to convert quickly between values.</p>
  
  <p>Fortunately, everything works up to this point (conversion, population, etc), except that, when I save the results, the unitModel does NOT save to the database. Does anybody have suggestions for what I can do to get this to work?</p>