title: Using PagedList with ViewModel
body: <p>Hi Guys really need your help in solving the problem while using PagedList with ViewModel(works perfectly with Domain Model).</p>
  
  <p>I am MVC beginner, here is what I have tried so far.</p>
  
  <p>/<strong>**********I have one model***********</strong>/</p>
  
  <pre><code>public class Property
  {        
      public int ID { get; set; }
      public int UserID { get; set; }
      public DateTime Created { get; set; }
      public DateTime Edited { get; set; }
  }
  </code></pre>
  
  <p>Created ViewModel out of it (will add more properties from other Domain model for the time being using only one Domain model</p>
  
  <pre><code>public class SearchResultsVM
  {
  
      public PagedList.IPagedList&lt;Property&gt; BasicDetails { get; set; }
  
  }
  </code></pre>
  
  <p>Controller Action Method:</p>
  
  <pre><code>public ActionResult SearchResults(string sortOrder, string SearchKeyword, string currentFilter, int? page)
  {
      ViewBag.CurrentSort = sortOrder;
      ViewBag.TitleSortParm = String.IsNullOrEmpty(sortOrder) ? "title_desc" : "";
      ViewBag.DateSortParm = sortOrder == "Date" ? "date_desc" : "Date";
      if (SearchKeyword != null){page = 1;}
      else{SearchKeyword = currentFilter;}
      ViewBag.CurrentFilter = SearchKeyword;            
      var sr = from s in db.Property
                            select s;          
      if (!String.IsNullOrEmpty(SearchKeyword))
      {sr = db.Property.Where(s =&gt;   s.PropertyTitle.ToUpper().Contains(SearchKeyword.ToUpper()));}
      switch (sortOrder)
      {
          case "title_desc":
              sr = sr.OrderByDescending(s =&gt; s.PropertyTitle);
              break;
          case "Date":
              sr = sr.OrderBy(s =&gt; s.Created);
              break;
          case "date_desc":
              sr = sr.OrderByDescending(s =&gt; s.Created);
              break;
          default:
              sr = sr.OrderBy(s =&gt; s.PropertyTitle);
              break;
      }
      SearchResultsVM srVM = new SearchResultsVM();
      int pageSize = 10;
      int pageNumber = (page ?? 1);
      srVM.BasicDetails = sr.ToList().ToPagedList(pageNumber,pageSize);
      return View(srVM);
  }
  </code></pre>
  
  <h2>My View</h2>
  
  <p>While Accessing the ViewModel in View I am not getting any properties of Property Domain Model</p>
  
  <pre><code>@model PagedList.IPagedList&lt;GH_Final.ViewModel.SearchResultsVM&gt;
  @using PagedList;
  @using PagedList.Mvc;
  
  @using (Html.BeginForm("SearchResults", "Home", FormMethod.Get))
  {
  &lt;p&gt;
      Find by name: @Html.TextBox("SearchKeyword", ViewBag.CurrentFilter as string)
      &lt;input type="submit" value="Search" /&gt;
  &lt;/p&gt;
  }
  
  
  @foreach (var item in Model)
  {
      &lt;tr&gt;
          &lt;td&gt;
              @Html.DisplayFor(modelItem =&gt; item.created)
          &lt;/td&gt;
          &lt;td&gt;
              @Html.DisplayFor(modelItem =&gt; item.BasicDetails.Created)
          &lt;/td&gt;
          &lt;td&gt;
              @Html.DisplayFor(modelItem =&gt; item.BasicDetails.PropertyDesc)
          &lt;/td&gt;
  </code></pre>