title: The model item passed into the dictionary is of type 'System.Collections.Generic.List`
body: <p>I am trying to do paging and sorting in my Index view without using PagedList. However I am encountering the error - </p>
  
  <blockquote>
    <p>The model item passed into the dictionary is of type  System.Collections.Generic.List`1[AQB_MON.Models.DeviceLog]', but this dictionary requires a model item of type 'AQB_MON.ViewModels.DeviceLogIndex'.</p>
  </blockquote>
  
  <p>I have created my own ViewModel to pass parameters to the Create View. When I enter the DeviceLog Index View it is for a specific DeviceID and I want to pass this DeviceID to the Create View however I encountered some issues using PagedList. So I found an alternative however I encounter the above error. </p>
  
  <p>My DeviceLogIndex ViewModel consists of - </p>
  
  <pre><code>public class DeviceLogIndex
  {
      public DeviceLogIndex()
      {
          this.DeviceLogs = new List&lt;DeviceLog&gt;();
      }
      public int DeviceID { get; set; }
      public string mytest { get; set; }
      public List&lt;DeviceLog&gt; DeviceLogs { get; set; }
  </code></pre>
  
  <p>and my PageInfo ViewModel that is used for Paging and sorting is -</p>
  
  <pre><code>public class PagingInfo
  {
      public string SortField { get; set; }
      public string SortDirection { get; set; }
      public int PageSize { get; set; }
      public int PageCount { get; set; }
      public int CurrentPageIndex { get; set; }
  }
  </code></pre>
  
  <p>the first part of my view is - </p>
  
  <pre><code>@model AQB_MON.ViewModels.DeviceLogIndex
  
  @{
  ViewBag.Title = "Index";
  }
  @{
  AQB_MON.ViewModels.PagingInfo info = ViewBag.PagingInfo;
  }
  </code></pre>
  
  <p>I am thinking the 'info' declaration is causing the problem?</p>
  
  <p>My controller is - </p>
  
  <pre><code>public ActionResult Index(int id)
  {
      var devicelogs = db.DeviceLogs
          .Include(d =&gt; d.Device)
          .Include(d =&gt; d.DeviceLogType)
          .Include(d =&gt; d.Device.ManufacturerModel)
          .Where(d =&gt; d.DeviceID == id);
      { 
          PagingInfo info = new PagingInfo();
              info.SortField = "DeviceLog";
              info.SortDirection = "ascending";
              info.PageSize = 15;
              info.PageCount = Convert.ToInt32(Math.Ceiling((double)(db.DeviceLogs.Count()/info.PageSize)));
              info.PageCount +=1;
              info.CurrentPageIndex = 0;
              var query = devicelogs.OrderBy(c =&gt; c.DeviceLogID).Take(info.PageSize);
              ViewBag.PagingInfo = info;
              List&lt;DeviceLog&gt; model= query.ToList();
  
          return View(model);
      }
  }
  
  [HttpPost]
  public ActionResult Index(PagingInfo info, int id)
  {
      var devicelogs = db.DeviceLogs
          .Include(d =&gt; d.Device)
          .Include(d =&gt; d.DeviceLogType)
          .Include(d =&gt; d.Device.ManufacturerModel)
          .Where(d =&gt; d.DeviceID == id);
      {
          IQueryable&lt;DeviceLog&gt; query = null;
          switch(info.SortField)
          {
              case "EntryDate":
                  query = (info.SortDirection == "ascending" ?
                      devicelogs.OrderBy(c =&gt; c.EntryDate) :
                      devicelogs.OrderByDescending(c =&gt; c.EntryDate));
                  break;
              case "LogType":
                 query = (info.SortDirection == "ascending" ?
                      devicelogs.OrderBy(c =&gt; c.DeviceLogType) :
                      devicelogs.OrderByDescending(c =&gt; c.DeviceLogType));
                  break;
          }
  
          query = query.Skip(info.CurrentPageIndex * info.PageSize).Take(info.PageSize);
          ViewBag.PagingInfo = info;
          List&lt;DeviceLog&gt; model = query.ToList();
          return View(model);
      }
  }
  </code></pre>