C# HtmlHelper不包含PagedListPager的定义
我是ASP.NET MVC新手,所以这个问题可能不会太复杂。我在向ASP.NET MVC项目添加分页时遇到问题。我已经从NuGet软件包安装程序安装了pagedlist.mvc,然后在控制器中编写了以下简单的索引代码,以传递分页列表:C# HtmlHelper不包含PagedListPager的定义,c#,html,asp.net-mvc,pagination,pagedlist,C#,Html,Asp.net Mvc,Pagination,Pagedlist,我是ASP.NET MVC新手,所以这个问题可能不会太复杂。我在向ASP.NET MVC项目添加分页时遇到问题。我已经从NuGet软件包安装程序安装了pagedlist.mvc,然后在控制器中编写了以下简单的索引代码,以传递分页列表: using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; using MvcMovie
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using MvcMovie.Data;
using MvcMovie.Models;
using PagedList;
namespace MvcMovie.Controllers
{
public class MoviesController : Controller
{
private readonly MvcMovieContext _context;
public MoviesController(MvcMovieContext context)
{
_context = context;
}
// GET: Movies
public IActionResult Index(int ? page)
{
var movies = from m in _context.Movies select m;
int pageSize = 3;
int pageNumber = (page ?? 1);
return View(movies.ToPagedList(pageNumber,pageSize));
}
然后,我更改了索引视图,并在顶部使用PagedList.Mvc添加了。我还将模型更改为@model PagedList.IPagedList
。视图文件如下所示:
@using PagedList.Mvc;
@model PagedList.IPagedList<MvcMovie.Models.Movie>
@{
ViewBag.Title = "Movie List";
}
<h1>Listă de filme</h1>
<p>
<a asp-action="Create">Adaugă film</a>
</p>
<table class="table">
<thead>
<tr>
<th>
@Html.DisplayNameFor(model => model.FirstOrDefault().Title)
</th>
<th>
@Html.DisplayNameFor(model => model.FirstOrDefault().ReleaseDate)
</th>
<th>
@Html.DisplayNameFor(model => model.FirstOrDefault().Genre)
</th>
<th>
@Html.DisplayNameFor(model => model.FirstOrDefault().Price)
</th>
<th></th>
</tr>
</thead>
<tbody>
@foreach (var item in Model)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.Title)
</td>
<td>
@Html.DisplayFor(modelItem => item.ReleaseDate)
</td>
<td>
@Html.DisplayFor(modelItem => item.Genre)
</td>
<td>
@Html.DisplayFor(modelItem => item.Price)
</td>
<td>
<a asp-action="Edit" asp-route-id="@item.MovieId">Editează</a> |
<a asp-action="Details" asp-route-id="@item.MovieId">Detalii</a> |
<a asp-action="Delete" asp-route-id="@item.MovieId">Șterge film</a>
</td>
</tr>
}
</tbody>
</table>
<br />
<div style="margin:5px;">
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 }))
</div>
@使用PagedList.Mvc;
@型号PagedList.IPagedList
@{
ViewBag.Title=“电影列表”;
}
电影目录
阿达格ă膜
@DisplayNameFor(model=>model.FirstOrDefault().Title)
@DisplayNameFor(model=>model.FirstOrDefault().ReleaseDate)
@DisplayNameFor(model=>model.FirstOrDefault().Genre)
@DisplayNameFor(model=>model.FirstOrDefault().Price)
@foreach(模型中的var项目)
{
@DisplayFor(modeleItem=>item.Title)
@DisplayFor(modelItem=>item.ReleaseDate)
@DisplayFor(modeleItem=>item.Genre)
@DisplayFor(modelItem=>item.Price)
Editează|
德塔利|
Șterge薄膜
}
@Model.PageCount的@页(Model.PageCountUrl.Action(“索引”),
新建{page,sortOrder=ViewBag.CurrentSort,currentFilter=ViewBag.currentFilter})
正如您所看到的,我在视图底部编写了显示分页的代码,但出现了错误:
“IHtmlHelper”不包含的定义
“PagedListPager”和最佳扩展方法重载
'HtmlHelper.PagedListPager(HtmlHelper,IPagedList,Func)'
需要“HtmlHelper”MvcMovie类型的接收器
我还尝试在视图文件顶部使用PagedList添加,但没有任何效果。您缺少PagedList的一个程序集引用。您需要从nuget package安装两个程序包
页面列表和
PagedList.mvc(参考下图)
如果已经安装,请重新安装或重新启动project我已多次重新启动该项目,现在两个软件包都重新安装了两次。还是一样的错误。