我通过PagedList
安装了PagedList.Mvc
和NuGet
个软件包。然后我以这样的方式使用它:
@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));
}
}
结果是否正常无序列表是否正常。然后我如何将自定义样式应用于寻呼机?
谢谢!
答案 0 :(得分:4)
这里的PagedList nuget包的创建者。
说实话,我不确定发生了什么 - 这让我很奇怪。根据您给出的描述,我最好的猜测是Url.Action("List", new {page = page})
返回null或空值,然后导致href
属性不呈现。您可以通过在视图中的其他位置添加以下代码并确保它返回真实的URL来测试:
<p>@Url.Action("List", new {page = 1})</p>
如果该段落标记为空,则问题最有可能出现在路由中。