1
我在我的索引視圖上使用PagedList,它工作正常,因爲它只是一個列表。因此,當我點擊下一頁按鈕時,它會針對索引運行,並拉下一組物品。我的問題是,在高級搜索後嘗試在我的結果頁上使用此功能時。我的搜索在返回結果中工作正常。有在查詢中使用50+的參數,有些是基於什麼檢查/選擇等。這裏是一個可能的查詢的示例包含或排除:如何在MVC的搜索結果頁面上使用PagedList?
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));
這可能會導致一個SQL查詢是這樣的:
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);
這裏是我的部分觀點:
@Html.PagedListPager(Model, page => Url.Action("Results", new { page }))
當我使用PagedList,結果還是回來了,但是當我點擊下頁它試圖通過將網址重新運行查詢。行動「結果「沒有任何價值和崩潰。我可以存儲結果並從中進行分頁嗎?是否有另一個分頁選項可以更好地工作?感謝您的任何建議。 :)