title: using a ViewModel for a partial view in a view
body: <p>I am curious how to do the following. I have a main view with parent data about support cases. I also will be showing a child list of MTM data using a partial view. I have built a ViewModel to supply the partial view with the data needed.</p>
  
  <p>Here is my ViewModel:</p>
  
  <pre><code>public class CaseComplaintsViewModel
      {
      public string ComplaintCode { get; set; }
      public string ComplaintType { get; set; }
      }
  </code></pre>
  
  <p>The ViewModel is based on data from these two domain models:</p>
  
  <pre><code>public class CaseComplaint
      {
      [Key]
      public int CaseComplaintID { get; set; }
      public int CasesID { get; set; }
      public int ComplaintCodeID { get; set; }
      public virtual Cases Cases { get; set; }
      public virtual ComplaintCode ComplaintCode { get; set; }
      }
  
  public class ComplaintCode
          {
          public int ComplaintCodeID { get; set; }
  
          [MaxLength(50)]
          [Required(ErrorMessage="Complaint Code is required")]
          public string ComplaintCodeName { get; set; }
  
          [MaxLength(50)]
          [Required(ErrorMessage="Complaint Type is required")]
          public string ComplaintType { get; set; }
  
          public virtual ICollection&lt;CaseComplaint&gt; CaseComplaint { get; set; }
  
          }
  </code></pre>
  
  <p>Pretty simple.</p>
  
  <p>Here is the partial view.</p>
  
  <pre><code>@model IEnumerable&lt;cummins_db.ViewModels.CaseComplaintsViewModel&gt;
  
  &lt;table width="100%"&gt;
  &lt;tr&gt;
  &lt;th&gt;Complaint Code&lt;/th&gt;
  &lt;th&gt;Complaint Description&lt;/th&gt;
  &lt;/tr&gt;  
  @foreach (var item in Model)
      {
  &lt;tr&gt;
      &lt;td&gt;
          @Html.DisplayFor(modelItem =&gt; item.ComplaintCode )    
      &lt;/td&gt;
      &lt;td&gt;
          @Html.DisplayFor(modelItem =&gt; item.ComplaintType)
      &lt;/td&gt;
  
  &lt;/tr&gt;
      }
  &lt;/table&gt;
  </code></pre>
  
  <p>This partial view will be used inside of my main Cases view. I will also periodically refresh this partial view using ajax.</p>
  
  <p>So my questions is, how do I get the correct data into the view when my main cases view opens? Does the partial view need it's own controller or do I handle that in the Cases controller?</p>