PagedList没有正确呈现
问题描述:
我通过NuGet
安装了PagedList
和PagedList.Mvc
包。里面控制器代码PagedList没有正确呈现
@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));
}
}
这是很正常的无样式的无序列表作为一个结果。那么我如何将自定义样式应用于传呼机?
谢谢!
答
PagedList nuget包的创建者在这里。
说实话,我不确定发生了什么 - 它让我觉得很奇怪。根据您给出的描述,我最好的猜测是Url.Action("List", new {page = page})
正在返回null或空值,然后导致href
属性不呈现。您可以通过在你看来其他地方添加以下代码,并确保它返回一个真正的URL测试:
<p>@Url.Action("List", new {page = 1})</p>
如果段落标记为空,那么问题很可能出在你的路由。
好的。我只有一个页面,所以'next/prev'链接被禁用。认为这是罪魁祸首?但是我现在正在获得的是没有造型的明显的不合格名单。这是正常的行为,我应该适用我的风格? – lexeme 2012-04-19 12:39:08
如果你没有包含pagedlist.css文件(或者你自己设计),这是正常的行为, – Troy 2012-04-19 23:12:58