title: How to use multiple models in one view for ASP.NET MVC?
body: <p>I've read similar questions on SO but can't seem to figure out this issue, which is specific to DBContext objects (I think). Here's some dummy code to illustrate.</p>
  
  <p>I have the following code in my Index() action:</p>
  
  <pre><code>    public ActionResult Index()
      {
          AnimalDBContext db = new AnimalDBContext();
  
          return View(db.Dogs);
      }
  </code></pre>
  
  <p>I have the following code for my models:</p>
  
  <pre><code>    public class Dog
      {
          public int ID { get; set; }
          public string name { get; set; }
          public string breed { get; set; }
      }
  
      public class AnimalDBContext : DbContext
      {
          public DbSet&lt;Dog&gt; Dogs { get; set; }
      }
  </code></pre>
  
  <p>In my view I have the following:</p>
  
  <pre><code>@model IEnumerable&lt;AnimalProject.Models.Dog&gt;
      @foreach (var d in Model)
      {
      &lt;h3&gt;@d.name&lt;/h3&gt;
      &lt;h2&gt;@d.breed&lt;/h2&gt;
      }
  </code></pre>
  
  <p>Everything works great, the view will loop through every dog in my database. However, I have another set of DBContext data from another table that I want in the same view. I want to be able to enumerate each item in the database for that table as well. </p>
  
  <p>This is what I want, if you catch my drift:</p>
  
  <pre><code>@model IEnumerable&lt;AnimalProject.Models.Dog&gt;
  @model IEnumerable&lt;AnimalProject.Models.Cat&gt;
      @foreach (var d in Dog)
      {
      &lt;h3&gt;@d.name&lt;/h3&gt;
      &lt;h2&gt;@d.breed&lt;/h2&gt;
      }
      @foreach (var c in Cat)
      {
      &lt;h3&gt;@c.name&lt;/h3&gt;
      &lt;h2&gt;@c.breed&lt;/h2&gt;
      }
  </code></pre>
  
  <p>I have tried grouping the classes together and using a partial view, but apparently you can't have a different model in a partial view, because I always get the error message: </p>
  
  <blockquote>
    <p>"The model item passed into the
    dictionary is of type
    'System.Data.Entity.DbSet<code>1[AnimalProject.Models.Dog]',
    but this dictionary requires a model
    item of type
    'System.Collections.Generic.IEnumerable</code>1[AnimalProject.Models.Cat]'."</p>
  </blockquote>
  
  <p>So, how can I use multiple models in my view that both get the data I want from separate tables in the database?</p>