title: How to use PagedList on search results page in MVC?
body: <p>I am using PagedList on my index view which works fine because it is just a list. So when I click on the next page button, it runs against index and pulls the next set of items. My issue is when trying to use this on my results page after an advanced search. My search works fine in returning results. There are 50+ parameters used in the query and some are include or exclude based on what is checked/selected etc. Here is an example of a possible query:</p>
  
  <pre><code>SQLstatement = string.Format("select * from Cards where {0} and {1} and (({2}) or ({3})) 
  and CardID In (Select CardID from CardAbilities where {4});", final, finalexcludefrommulti, 
  finalsplit, finalmulti, finalability);
  var CardList = db.Cards.SqlQuery(SQLstatement).ToList();
  var pageNumber = page ?? 1;
              int pageSize = 5;
              ViewBag.OnePageOfCards = pageNumber;
              return View(CardList.ToPagedList(pageNumber, pageSize));
  </code></pre>
  
  <p>This could result in a SQL Query like this:</p>
  
  <pre><code>select * from Cards where maintypeid = 1 and redbluemanacost is null 
  and redblackmanacost is null and blueblackmanacost is null 
  and redmanacost is null and bluemanacost is null and blackmanacost is null 
  and ((whitegreenmanacost &gt; 0  or redgreenmanacost &gt; 0 or greenbluemanacost &gt; 0  
  or greenblackmanacost &gt; 0 or greenorlifecost &gt; 0  or whitegreenmanacost &gt; 0  
  or redwhitemanacost &gt; 0 or whitebluemanacost &gt; 0 or whiteblackmanacost &gt; 0  
  or whiteorlifecost &gt; 0 ) or (greenmanacost &gt; 0  or whitemanacost &gt; 0 )) 
  and CardID In (Select CardID from CardAbilities 
  where abilityid = 3 or abilityid = 1007);
  </code></pre>
  
  <p>Here is part of my view:</p>
  
  <pre><code> @Html.PagedListPager(Model, page =&gt; Url.Action("Results",  new { page }))
  </code></pre>
  
  <p>When I use the PagedList, the results still come back, but when I click on next page it tries to rerun the query by going to Url.Action "Results" without any values and crashes. Can I store the results and have paging from that? Is there another paging option that would work better? Thanks for any advice. :)</p>