title: Reference Multiple Models in One MVC View
body: <p>Ia m trying to learn MVC and have been following the Getting Started with Entity Framework 6 Code First using MVC 5 (<a href="https://www.asp.net/mvc/overview/getting-started/getting-started-with-ef-using-mvc/creating-an-entity-framework-data-model-for-an-asp-net-mvc-application" rel="nofollow noreferrer">https://www.asp.net/mvc/overview/getting-started/getting-started-with-ef-using-mvc/creating-an-entity-framework-data-model-for-an-asp-net-mvc-application</a>) but change it to be a little drinks generator program (basically taking parts out and using my own idea to try and learn).</p>
  
  <p>I have created a personController, Person (Index, Create, Delete, Details &amp; Edit) Views and a person class which is listed below: </p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.ComponentModel;
  using System.ComponentModel.DataAnnotations;
  using System.ComponentModel.DataAnnotations.Schema;
  
  
  namespace DOSTeaDecider.Models
  {
      public class Person
      {
          public int ID { get; set; }
          [DisplayName("First Name")]
          public string FirstName { get; set; }
          [DisplayName("Last Name")]
          public string LastName { get; set; }
          //public byte[] Photo { get; set; }
          [DisplayName("Biography")]
          public string bio { get; set; }
          [DisplayName("Drink Choice")]
          public string Drink { get; set; }
          [DisplayName("Sugar Amount")]
          public int Sugar { get; set; }
          [DisplayName("Milk Colour")]
          public string MilkColour { get; set; }
          [DisplayName("Milk Dosage")]
          public string MilkDose { get; set; }       
  
      }
  }
  </code></pre>
  
  <p>In my view I would like to display the people based off the properties set in the model so I have something like the following which works great; however in the tutorial I am following they are using PagedList e.g. <code>@model PagedList.IPagedList&lt;ContosoUniversity.Models.Student&gt;</code> in the view and then they are able to call the properties of <code>PagedList.IPagedList</code> from the view. The problem I have is if I include two <code>@model</code> declarations in the view it doesn't like it but if I remove the reference to the person model I can't use the person properties, e.g. <code>model.LastName</code> and if I remove the reference to the PagedList.IPagedList I am unable to call the properties from this, e.g., <code>Model.PageCount</code>:</p>
  
  <pre><code>@model IEnumerable&lt;DOSTeaDecider.Models.Person&gt;
  @*@model PagedList.IPagedList&lt;DOSTeaDecider.Models.Person&gt;*@
  @*@using PagedList.Mvc;*@
  @{
      ViewBag.Title = "Index";
  }
  
  &lt;h2&gt;Index&lt;/h2&gt;
  
  &lt;p&gt;
      @Html.ActionLink("Create New", "Create")
  &lt;/p&gt;
  @using (Html.BeginForm("Index", "Person", FormMethod.Get))
  {
      &lt;p&gt;
          Find by name: @Html.TextBox("SearchString", ViewBag.CurrentFilter as string)
          &lt;input type="submit" value="Search" /&gt;
      &lt;/p&gt;
  }
  &lt;table class="table"&gt;
      &lt;tr&gt;
          &lt;th&gt;
              @Html.ActionLink("First Name", "Index", new { sortOrder = ViewBag.NameSortParm, currentFilter = ViewBag.CurrentFilter })
              @*@Html.DisplayNameFor(model =&gt; model.FirstName)*@
          &lt;/th&gt;
          &lt;th&gt;
              @Html.DisplayNameFor(model =&gt; model.LastName)
          &lt;/th&gt;
          &lt;th&gt;
              @Html.DisplayNameFor(model =&gt; model.Drink)
          &lt;/th&gt;
          &lt;th&gt;
              @Html.DisplayNameFor(model =&gt; model.Sugar)
          &lt;/th&gt;
          &lt;th&gt;
              @Html.DisplayNameFor(model =&gt; model.MilkColour)
          &lt;/th&gt;
          &lt;th&gt;
              @Html.DisplayNameFor(model =&gt; model.MilkDose)
          &lt;/th&gt;
          &lt;th&gt;&lt;/th&gt;
      &lt;/tr&gt;
  
  @foreach (var item in Model) {
      &lt;tr&gt;
          &lt;td&gt;
              @Html.DisplayFor(modelItem =&gt; item.FirstName)
          &lt;/td&gt;
          &lt;td&gt;
              @Html.DisplayFor(modelItem =&gt; item.LastName)
          &lt;/td&gt;
          &lt;td&gt;
              @Html.DisplayFor(modelItem =&gt; item.Drink)
          &lt;/td&gt;
          &lt;td&gt;
              @Html.DisplayFor(modelItem =&gt; item.Sugar)
          &lt;/td&gt;
          &lt;td&gt;
              @Html.DisplayFor(modelItem =&gt; item.MilkColour)
          &lt;/td&gt;
          &lt;td&gt;
              @Html.DisplayFor(modelItem =&gt; item.MilkDose)
          &lt;/td&gt;
          &lt;td&gt;
              @Html.ActionLink("Edit", "Edit", new { id=item.ID }) |
              @Html.ActionLink("Details", "Details", new { id=item.ID }) |
              @Html.ActionLink("Delete", "Delete", new { id=item.ID })
          &lt;/td&gt;
      &lt;/tr&gt;
  }
  
  &lt;/table&gt;
  &lt;br /&gt;
  Page @(Model.PageCount &lt; Model.PageNumber ? 0 : Model.PageNumber) of @Model.PageCount
  
  @Html.PagedListPager(Model, page =&gt; Url.Action("Index",
      new { page, sortOrder = ViewBag.CurrentSort, currentFilter = ViewBag.CurrentFilter }))
  </code></pre>
  
  <p>I have tried to research and creating references in the person model to the PagedList but so far my efforts have failed. I think I may be missing something simple, but I am learning and that's why I have asked on here so that maybe someone could please advise.</p>