title: How to Fix " The model item passed into the dictionary is of type but this dictionary requires a model item of type "
body: <p>I want to make paging in the table using Pagedlist and get an error </p>
  
  <blockquote>
    <p>The model item passed into the dictionary is of type 'PagedList.PagedList<code>1[System.Collections.Generic.KeyValuePair</code>2[MyProject.Data.Models.User,System.Collections.Generic.IEnumerable`1[MyProject.Data.Models.Role]]]', but this dictionary requires a model item of type</p>
  </blockquote>
  
  <p>I can make paging but only for one model like using code <em>"View(db.Roles.ToList().ToPagedList(pageNumber, pageSize))"</em>. But for this case it's different, here I use two models namely User and Role. I use a dictionary to call the two models. I am confused about how to implement it in view using PagedList. This is the code that I have tried.Thanks</p>
  
  <pre><code>public ActionResult Index(int? page)
  {
      int pageSize = 2;
      int pageNumber = (page ?? 1);
      Dictionary&lt;User, IEnumerable&lt;Role&gt;&gt; userRoles = userRoleRepo.GetDictionary_UserAndRolesOfEachUser();
     return View(userRoles.ToPagedList(pageNumber, pageSize));
  }
  </code></pre>
  
  <p>View</p>
  
  <pre><code> @model PagedList.IPagedList&lt;Dictionary&lt;MyProject.Data.Models.User, IEnumerable&lt;MyProject.Data.Models.Role&gt;&gt;&gt;
   &lt;table class="table"&gt;
      &lt;tr class="header"&gt;
          &lt;th&gt; UserName&lt;/th&gt;
          &lt;th&gt; FullName&lt;/th&gt;
      &lt;/tr&gt;
       @foreach (Dictionary&lt;MyProject.Data.Models.User, IEnumerable&lt;MyProject.Data.Models.Role&gt;&gt; item in Model)
       {
          &lt;tr class="detail"&gt;
              &lt;td&gt;
                  @Html.DisplayFor(modelItem =&gt; item.First().Key.UserName)
              &lt;/td&gt;
              &lt;td&gt;
                  @Html.DisplayFor(modelItem =&gt; item.First().Key.FullName)
              &lt;/td&gt;
              &lt;td&gt;
                  &lt;ul&gt;
                      @foreach (var role in item.First().Value)
                      {
                          &lt;li&gt;
                              @Html.DisplayFor(modelItem =&gt; role.RoleName)
                          &lt;/li&gt;
                      }
                  &lt;/ul&gt;
              &lt;/td&gt;
          &lt;/tr&gt;
       }
   &lt;/table&gt;
  
      Page @(Model.PageCount &lt; Model.PageNumber ? 0 : Model.PageNumber) of @Model.PageCount
      @Html.PagedListPager(Model, page =&gt; Url.Action("Index", new { page}))
  </code></pre>