title: How to return ViewModel PagedList [ASP MVC]
body: <p>I'm trying to return a category page with paging .... I got a problem with that in my view , I can't handle the View Model Members , and can't to control them ...</p>
  <p>Here is my ViewModel:</p>
  <pre><code>public class CategoryVm
  {
      public List&lt;Book&gt; Book { set; get; }
  
      public Category Category_Content { get; set; }
  
      
  }
  </code></pre>
  <p>Also here is the controller :</p>
  <pre><code>public ActionResult Category(int? id, int? page)
      {
          int pageSize = 6;
          int pageNumber = page ?? 1;
          if (id != null)
          {
              var vm = new CategoryVm();
              vm.Category_Content = db.Categories.Where(t =&gt; t.Category_id == id).Single();
              vm.Book = db.Books.Where(b =&gt; b.Category_id == id).ToList();
              if (vm != null)
              {
                  //Here I have the problem , it telling me that 'CategoryVm' does not contain a definition for 'ToPagedList'
                  return View(vm.ToPagedList(pageNumber, pageSize));
  
              }
              return HttpNotFound();
          }
  
          return RedirectToAction(&quot;index&quot;,new { Controller = &quot;Home&quot; });
      }
  </code></pre>
  <p>and here is my view :</p>
  <pre><code>@using PagedList.Mvc
  @model PagedList.IPagedList&lt;SmartBookLibrary.ViewModel.CategoryVm&gt;
  
  @{
      ViewBag.Title = Model.Category_Content.Category_name+ &quot; - Smart Books Library&quot;;
  }
  
      &lt;div class=&quot;container&quot;&gt;
  
      &lt;div class=&quot;row&quot;&gt;
  
          &lt;div class=&quot;col-md-3&quot;&gt;
              &lt;p class=&quot;lead&quot;&gt;Categories&lt;/p&gt;
              &lt;div class=&quot;list-group&quot;&gt;
                  &lt;a href=&quot;#&quot; class=&quot;list-group-item&quot;&gt;Developers&lt;/a&gt;
              &lt;/div&gt;
          &lt;/div&gt;
  
          &lt;div class=&quot;col-md-9&quot;&gt;
  
              
  
              &lt;div class=&quot;row&quot;&gt;
  @foreach (var item in Model.Book)
  {
                  
                  &lt;div class=&quot;col-sm-4 col-lg-4 col-md-4&quot;&gt;
  
                      &lt;figure class=&quot;snip1091 navy&quot;&gt;
                          &lt;img src=&quot;~/Images/@item.Book_Image&quot; alt=&quot;sq-sample6&quot; /&gt;
                          &lt;figcaption&gt;
                              &lt;label&gt;@item.Book_name&lt;/label&gt;
                          &lt;/figcaption&gt;&lt;a href=&quot;/Category/@item.Category.Category_id&quot;&gt;&lt;/a&gt;
                      &lt;/figure&gt;
  
  
                      
                  &lt;/div&gt;
  }
  
  
              &lt;/div&gt;
              Page @(Model.PageCount &lt; Model.PageNumber ? 0 : Model.PageNumber) of @Model.PageCount
              @Html.PagedListPager(Model, page =&gt; Url.Action(&quot;Category&quot;, new {page}))
  
  
          &lt;/div&gt;
  
      &lt;/div&gt;
  
  &lt;/div&gt;
  </code></pre>
  <p>I the view I can't access the model :</p>
  <blockquote>
  <p>ViewBag.Title = Model.<strong>Category_Content</strong></p>
  <p>@foreach (var item in Model.<strong>Book</strong>)</p>
  </blockquote>
  <p>so how to fix that , and make the paging work ??</p>