如果我在这个例子中有50条记录,那么如何在下一页继续使用IPagedList计算记录数。
表i中的使用此代码计算:
int a = 1;
@(a++)
对于iPagedList我使用此代码:
@ Html.PagedListPager(Model,page => Url.Action(“Index”,new { 页, searchBy = Request.QueryString [“searchBy”], search = Request.QueryString [“search”] }),
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 ...等。
如何解决?
答案 0 :(得分:1)
我解决了这个问题。 我修改了COntroller代码:
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);
我还将此代码添加到View:
int pageno = (int)ViewBag.pageno;
int itemperpage = (int)ViewBag.itemperpage;
int currentno = ((pageno - 1) * itemperpage) + 1;
@( currentno++ )