title: Using an interface as the model type of a partial view + data annotations
body: <p>I have a case where a complex partial view needs different validation of fields depending on where the partial view is used.</p>
  
  <p>I thought I could get around this by making the partial view take an interface as the model type and implementing two different ViewModels based on the interface.  The data annotations in the two ViewModels would be different.  I would then supply an instance of the correct ViewModel to the partial view.  </p>
  
  <p>But what I'm finding is that the only annotations that are recognized are those on the interface itself.  DAs on the interface-implementing ViewModel classes are ignored, even though those are the objects that are being passed as models.  So my plan isn't working.</p>
  
  <p>Is there a way around this?  A better approach?  I'd prefer not to split the partial view into separate views if I can avoid it.  </p>
  
  <p>ETA:  This is an abbreviated version of the partial view, as requested:</p>
  
  <pre><code>@model IPerson
  @Html.ValidationSummary(false)
  &lt;fieldset&gt;
      &lt;table class="editForm"&gt;
          &lt;tr&gt;
              &lt;td class="editor-label"&gt;
                  @Html.LabelFor(model =&gt; model.FirstName)
              &lt;/td&gt;
              &lt;td class="editor-field"&gt;
                  @Html.EditorFor(model =&gt; model.FirstName)
                  @Html.ValidationMessageFor(model =&gt; model.FirstName)
              &lt;/td&gt;
              &lt;td class="editor-label"&gt;
                  @Html.LabelFor(model =&gt; model.LastName)
              &lt;/td&gt;
              &lt;td class="editor-field"&gt;
                  @Html.EditorFor(model =&gt; model.LastName)
                  @Html.ValidationMessageFor(model =&gt; model.LastName)
              &lt;/td&gt;
          &lt;/tr&gt;
       &lt;/table&gt;
    &lt;fieldset&gt;
  </code></pre>
  
  <p>The real partial view is quite long and has a lot of @if statements managing the rendering (or not) of optional sections, but it doesn't do anything tricky.  </p>