Pagedlist分页链接中的Href属性为空

时间:2019-04-17 17:33:29

标签: c# asp.net-mvc razor pagedlist

PagedListPager方法正在生成分页链接(锚标记),但是它们的href属性为Empty / Null。查看图片

enter image description here

视图中的代码

@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));
            }
        }

1 个答案:

答案 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 })