当我在此示例中拥有超过 50 条记录时,如何在下一页上继续使用 IPgedList 计算记录数。
在表中我用这个代码进行计数:
int a = 1;
@(a++)
对于 iPagedList 我使用以下代码:
@Html.PagedListPager(模型, 页面 => Url.Action("索引", new { 页, searchBy = Request.QueryString["searchBy"], 搜索 = Request.QueryString["搜索"] }),
new PagedListRenderOptions()
{
LinkToFirstPageFormat = "<< Прва",
LinkToPreviousPageFormat = "< Претходна",
LinkToNextPageFormat = "Следна >",
LinkToLastPageFormat = "Последна >>",
Display = PagedListDisplayMode.IfNeeded,
DisplayPageCountAndCurrentLocation = false,
PageCountAndCurrentLocationFormat = "Страна {0} од {1}.",
DisplayItemSliceAndTotal = true,
ItemSliceAndTotalFormat = "Прикажувам од {0} до {1}, од вкупно {2}.",
MaximumPageNumbersToDisplay = 5
}
)
控制器代码:
var tbl_patnici = db.tbl_patnici.Include(t => t.tbl_agenti);
return View(tbl_patnici.ToList().OrderByDescending(x => x.pID).ToList().ToPagedList(page ?? 1, 50));
现在我限制每页50条记录,如果我转到下一页,计数器再次从1,2,3....等开始,而不是继续51,52,53...等
如何解决?
我解决了这个问题。 我修改了控制器代码:
var tbl_patnici = db.tbl_patnici.Include(t => t.tbl_agenti);
var items = tbl_patnici.OrderByDescending(x => x.pID).ToList();
var pageNumber = page ?? 1;
var onePageOfitmes = (items.ToPagedList(pageNumber, 50));
ViewBag.pageno = pageNumber;
ViewBag.itemperpage = 50;
return View(onePageOfitmes);
我还将此代码添加到视图中:
int pageno = (int)ViewBag.pageno;
int itemperpage = (int)ViewBag.itemperpage;
int currentno = ((pageno - 1) * itemperpage) + 1;
@( currentno++ )