title: Unable to add to IPagedList object or transfer List<T> to IPagedList<T>
body: <p>I'm using the <a href="https://github.com/TroyGoode/PagedList" rel="nofollow">Page List</a> ASP MVC plugin to add paging to my View as my view model contains a list that gets a little out of control at time. However, I'm running into a few issues. </p>
  
  <ul>
  <li>The view model contains a <code>List&lt;T&gt;</code> of another model object. If I make one query to the database, I'm able to change the data type of this list from <code>List&lt;ZipCodeTerritory&gt;</code> to <code>IPagedList&lt;ZipCodeTerritory&gt;</code>, then simply follow the documentation to load the list from the query like so: </li>
  </ul>
  
  <p><strong>View Model</strong></p>
  
  <pre><code>public IPagedList&lt;ZipCodeTerritory&gt; zipCodeTerritory { get; set; }
  </code></pre>
  
  <p><strong>Controller</strong></p>
  
  <pre><code>search.zipCodeTerritory = (from z in db.ZipCodeTerritory
                            where z.StateCode.Equals(search.searchState) &amp;&amp;
                                  z.EffectiveDate &gt;= effectiveDate
                           select z).ToList().ToPagedList(pageNumber, pageSize);
  
  //This works but this only covers one of the three different searches that are 
  //possibly from this Index page
  </code></pre>
  
  <ul>
  <li>However, this presents a couple issues. For one, I'm unable to use the <code>.clear</code> method a C# <code>List</code> uses. Second, and more importantly, if I need to perform a different search where I hit the database a couple times and add the result of each query to the <code>zipCodeTerritory</code> list, I'm unable to call the <code>.addRange()</code> method. Does anyone know how to add items to an <code>IPagedList</code>? </li>
  </ul>
  
  <p><strong>View Model</strong></p>
  
  <pre><code>public IPagedList&lt;ZipCodeTerritory&gt; zipCodeTerritory { get; set; }
  </code></pre>
  
  <p><strong>Controller</strong></p>
  
  <pre><code>foreach (var zip in zipArray)
  {
      var item = from   z in db.ZipCodeTerritory
                  where  z.ZipCode.Equals(zip) &amp;&amp;
                          z.EffectiveDate &gt;= effectiveDate &amp;&amp;
                          z.IndDistrnId.Equals(search.searchTerritory) &amp;&amp;
                          z.StateCode.Equals(search.searchState)
                  select z;
      search.zipCodeTerritory.AddRange(item); //This line throws the following exception:
  
      //PagedList.IPagedList&lt;Monet.Models.ZipCodeTerritory&gt;' does not contain a 
      //definition for 'AddRange' and no extension method 'AddRange' accepting a first 
      //argument of type 'PagedList.IPagedList&lt;Monet.Models.ZipCodeTerritory&gt;' could be 
      //found (are you missing a using directive or an assembly reference?)
  } 
  </code></pre>
  
  <ul>
  <li>I also tried simply leaving the code as it was prior to adding the paging, then just trying to cast the <code>List&lt;T&gt;</code> into an <code>IPagedList&lt;T&gt;</code> object, however this didn't work either. This method would solve all my above problems, so if anyone knows how to simply convert a <code>List</code> to and <code>IPagedList</code> that would be GREATLY appreciated. </li>
  </ul>
  
  <p><strong>View Model</strong></p>
  
  <pre><code>    public IPagedList&lt;ZipCodeTerritory&gt; pagedTerritoryList { get; set; }
      public List&lt;ZipCodeTerritory&gt; zipCodeTerritory { get; set; }
  </code></pre>
  
  <p><strong>Controller</strong></p>
  
  <pre><code>search.pagedTerritoryList = (IPagedList&lt;ZipCodeTerritory&gt;)search.zipCodeTerritory;
  
  //This threw the following exception at runtime: 
  //Unable to cast object of type  
  //System.Collections.Generic.List'1[Monet.Models.ZipCodeTerritory]' to type 
  //'PagedList.IPagedList'1[Monet.Models.ZipCodeTerritory]'.
  </code></pre>