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:
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));
This could result in a SQL Query like this:
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 > 0 or redgreenmanacost > 0 or greenbluemanacost > 0
or greenblackmanacost > 0 or greenorlifecost > 0 or whitegreenmanacost > 0
or redwhitemanacost > 0 or whitebluemanacost > 0 or whiteblackmanacost > 0
or whiteorlifecost > 0 ) or (greenmanacost > 0 or whitemanacost > 0 ))
and CardID In (Select CardID from CardAbilities
where abilityid = 3 or abilityid = 1007);
Here is part of my view:
@Html.PagedListPager(Model, page => Url.Action("Results", new { page }))
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. :)