title: PagedList working with ViewModels and .Skip().Take()
body: <p>I have an Action in my Controller to get a list of <code>MyObjectViewModels</code>. </p>
  
  <p>Inside that Action method, I call a method (Service layer) that fetches the relevant Models by applying a bunch of <code>LINQ</code> methods and returns a <code>IQueryable&lt;MyObject&gt;</code>.</p>
  
  <p>Then I do some sorting on the returned <code>IQueryable</code> and afterwards, ideally, I would perform a <code>.Skip(...).Take(25)</code> in the resulting <code>IQueryable</code>, convert it to a List, iterate over the 25 <code>MyObject</code> elements and convert them into my <code>MyObjectViewModels</code> class. I'd then return a <code>PagedList</code> with those ViewModels:</p>
  
  <pre><code>public ActionResult MyAction(...parameters...)
  {
      // Supose this returns 100000 records...
      IQueryable&lt;MyObject&gt; myObjs = _myService.GetMyObjects(...some params...);     
  
      // Sort and take only 25 (apply paging)
      IQueryable&lt;MyObject&gt; mySortedAndPagedObjs = myObjs.OrderBy(...);
      mySortedAndPagedObjs = mySortedAndPagedObjs.Skip(...).Take(25);
  
      List&lt;MyObject&gt; myObjsList = mySortedAndPagedObjs.ToList();
      List&lt;MyObjectViewModel&gt; myVMList = new List&lt;MyObjectViewModel&gt;();
  
      // *** Conversion loop ***
      foreach(MyObject myObj in myObjectList)
      {
         // ... convert the 25 MyObject to MyObjectViewModel 
         // and add them to the myVMList...
      }
  
      // Return a View with the PagedList
      return View(myVMList.ToPagedList(pageNumber, pageSize));
      // --&gt; The PagedList will not "know" that it is looking at 25 records of a 100000 long list!
  }
  </code></pre>
  
  <p>This, seems incompatible with the <a href="https://www.nuget.org/packages/PagedList.Mvc" rel="nofollow">PagedList.MVC</a> approach, which expects the <code>ToPagedList()</code> method to receive the <em>entire</em> set of objects (not just the 25 - I assume it internally calls the <code>.Skip().Take()</code> call itself). That would, however, force me to apply that conversion loop on the entire set of MyObject (!!) when I'd rather just do it for the 25 items I want to return at a time...</p>
  
  <p><strong>How can I get my <code>PagedList</code> to show the <code>ViewModels</code> chosen from a subset (e.g. 25 records) of a table with lots of data?</strong></p>