我正在尝试将分页功能插入其他公司的现有应用程序版本中。我在cshtml时遇到错误:
编译器错误消息:CS1928:'System.Web.Mvc.HtmlHelper>'不包含'PagedListPager'的定义,最佳扩展方法重载'PagedList.Mvc.HtmlHelper.PagedListPager(System.Web.Mvc.HtmlHelper ,PagedList.IPagedList,System.Func)'包含一些无效的参数
源错误:
编译器错误消息:CS1928:'System.Web.Mvc.HtmlHelper>'不包含'PagedListPager'的定义,最佳扩展方法重载'PagedList.Mvc.HtmlHelper.PagedListPager(System.Web.Mvc.HtmlHelper ,PagedList.IPagedList,System.Func)'包含一些无效的参数
源错误:
@ Html.PagedListPager(Model,page => Url.Action(“ Index”, 新建{页面,sortOrder = ViewBag.CurrentSort,currentFilter = ViewBag.CurrentFilter}))
控制器:
public ActionResult Index(int? page, string sortOrder, string currentFilter, int? managerGroupId, int? userGroupId, bool deletedBooks = false)
{
var models = new LibraryViewModel[] { };
models = Repository.LibrariesAsViewModels(managerGroup: managerGroupId, userGroup: userGroupId, includeInactive: deletedBooks)
.Where(p => p.ParentID.HasValue == false).OrderByDescending(p => p.SortOrder)
.Where(p => deletedBooks ? p.IsActive == false : true)
.ToArray();
ViewBag.CurrentSort = sortOrder;
ViewBag.currentFilter = currentFilter;
int pageSize = 6;
int pageNumber = (page ?? 1);
// var model = new PageModelList<LibraryViewModel>(); **original code
// model.Items = models; ** original code
var modelnew = new PageModelList<LibraryViewModel>();
modelnew.PList = models.ToPagedList(pageNumber, pageSize);
// return view(model) **original code
return View(modelnew);
}
public class PageModelList<T> : PageModel
{
public IEnumerable<T> Items { get; set; }
public int Count
{
get
{
if (Items == null)
{
return 0;
}
return Items.Count();
}
}
public IPagedList<T> PList { get; set; }
}
@using PagedList.Mvc;
@using PagedList;
@model PageModelList<LibraryViewModel>
@*model PagedList.IPagedList<PageModelList<LibraryViewModel>> --Commented out, there is error*@
<link href="~/Content/PagedList.css" rel="stylesheet" type="text/css" />
<div class="text-center">
<ul class="pagination">
@*Page @(Model.PageCount < Model.PageNumber ? 0 : Model.PageNumber) of @Model.PageCount*@
@Html.PagedListPager(Model, page => Url.Action("Index",
new { page, sortOrder = ViewBag.CurrentSort, currentFilter = ViewBag.CurrentFilter }))
</ul>
</div>
答案 0 :(得分:1)
@Html.PagedListPager
的参数必须是IPagedList
的类型,而不是PageModelList
的类型。您必须在控制器中进行更改以返回IPagedList类型的模型,并且还必须在视图中更改@model
语句。
@model IPagedList<LibraryViewModel>