我通过NuGet安装了PagedList和PagedList.Mvc包。然后我以这样的方式使用它:
@using PagedList;
@using PagedList.Mvc;
@model IPagedList<Employee>
@{
ViewBag.Title = "ListEmployees";
}
<h3>All Employees (@ViewBag.TotalEmployees)</h3>
@if(Model.Count > 0)
{
foreach(var item in Model)
{
Html.RenderPartial("Employee.Card", item);
}
@Html.PagedListPager((IPagedList)Model, page => Url.Action("List", new { page = page }), PagedListRenderOptions.Minimal)
}
else
{
@: no records were found. Sorry
}使用控制器内部的代码:
public class EmployeeController : Controller
{
private IRepository<Employee> repository;
private Int32 PageSize = 10;
public EmployeeController(IRepository<Employee> repository)
{
this.repository = repository;
}
public ActionResult List(Int32? page)
{
var set = repository.Get();
ViewBag.TotalEmployees = set.Count();
return View(set.ToPagedList(page ?? 1, PageSize));
}
}结果是无样式的无序列表是正常的吗?那么我该如何将我的自定义样式应用于pager呢?
谢谢!
发布于 2012-04-19 20:12:22
这里是PagedList nuget包的创建者。
老实说,我不知道发生了什么--这让我觉得很奇怪。根据您给出的描述,我最好的猜测是Url.Action("List", new {page = page})返回一个null或空值,这将导致href属性无法呈现。您可以通过在视图中的其他位置添加以下代码来测试这一点,并确保它返回一个真正的URL:
<p>@Url.Action("List", new {page = 1})</p>
如果段落标记为空,那么问题很可能出在路由上。
https://stackoverflow.com/questions/10222444
复制相似问题