PagedListPager方法正在生成分页链接(锚标记),但是它们的href属性为Empty / Null。查看图片
视图中的代码
@Html.PagedListPager(Model, page => Url.Action("Orders", new { page, size = Model.PageSize }), new PagedListRenderOptions() { Display = PagedListDisplayMode.IfNeeded })
已添加名称空间
@using PagedList;
@using PagedList.Mvc;
@model IPagedList<eRepository.Models.Orders>
控制器方法
public ActionResult Orders(int? page)
{
using (_context db = new _context())
{
return View(db.userorders.Where(s => s.status == 1).OrderBy(d => d.cdate).ToPagedList(page ?? 1, 10));
}
}
答案 0 :(得分:2)
您应该执行以下操作:
控制器:
public ActionResult Orders(int? page)
{
var model = db.Orders.ToList();
int pageSize = 3;
int pageNumber = (page ?? 1);
return View(model.ToPagedList(pageNumber, pageSize));
}
查看:
@using PagedList;
@using PagedList.Mvc
@model IPagedList<Store.Models.Orders>
@Html.PagedListPager(Model, page => Url.Action("Index", new { page }), new PagedListRenderOptions() { Display = PagedListDisplayMode.IfNeeded })