«IHtmlHelper <IPagedList <Cl>>» не содержит определения для «PagedListPager» - PullRequest
0 голосов
/ 26 марта 2019

У меня есть эта ошибка

'IHtmlHelper>' не содержит определения для 'PagedListPager' и лучшая перегрузка метода расширения 'HtmlHelper.PagedListPager (HtmlHelper, IPagedList, Func)' требует получателятипа 'HtmlHelper'

, когда я хочу показать Paged List, и я не могу найти решение для этого.

И ошибка в этой строке ->

@Html.PagedListPager(Model, page => Url.Action("Index", new { page, sortOrder = ViewBag.CurrentSort, currentFilter = ViewBag.CurrentFilter }))

Мой индекс:

@model PagedList.IPagedList<AdminPanel_V1.Models.Cl>
@using PagedList.Mvc;
@using System.Web;
<link href="~/Content/PagedList.css" rel="stylesheet" type="text/css" />

@{
    ViewBag.Title = "Clientes";
}

<section class="content-header">
    <h1>
        Clientes
    </h1>
    <ol class="breadcrumb">
        <li><a href="#"><i class="fa fa-dashboard"></i> Home</a></li>
        <li class="active">Clientes</li>
    </ol>
</section>
<!-- Main content -->
<section class="content">
    <div class="row">
        <div class="col-xs-12">
            <div class="box">
                <div class="box-header">
                    <h3 class="box-title">Gestão de Clientes</h3>
                    <a style="float:right" class="btn btn-primary" href="/Clientes/Create/"><i class="fa fa-user-plus"> Adicionar Cliente</i></a>
                </div>
                <!-- /.box-header -->
                <div class="box-body">
                    @using (Html.BeginForm("Index", "Clientes", FormMethod.Get))
                    {
                        <p>
                            Pesquisa: @Html.TextBox("SearchString", ViewBag.CurrentFilter as string)
                            <input type="submit" value="Search" />
                        </p>
                    }
                    <table id="example1" class="table table-bordered table-striped">
                        <thead>
                            <tr>
                                <th>@Html.ActionLink("Id", "Index", new { sortOrder = ViewBag.NameSortParm, currentFilter = ViewBag.CurrentFilter })</th>
                                <th>@Html.ActionLink("Nome", "Index", new { sortOrder = ViewBag.NameSortParm, currentFilter = ViewBag.CurrentFilter })</th>
                                <th>@Html.ActionLink("Email", "Index", new { sortOrder = ViewBag.NameSortParm, currentFilter = ViewBag.CurrentFilter })</th>
                                <th>@Html.ActionLink("Telefone", "Index", new { sortOrder = ViewBag.NameSortParm, currentFilter = ViewBag.CurrentFilter })</th>
                                <th>@Html.ActionLink("Número de Contribuinte", "Index", new { sortOrder = ViewBag.NameSortParm, currentFilter = ViewBag.CurrentFilter })</th>
                                <th><i class="fa fa-cog"> Opções</i></th>
                            </tr>
                        </thead>
                        <tbody>
                            @foreach (var item in Model)
                            {
                                <tr>
                                    <td>@Html.DisplayFor(modelItem => item.No)</td>
                                    <td>@Html.DisplayFor(modelItem => item.Nome)</td>
                                    <td>@Html.DisplayFor(modelItem => item.Email)</td>
                                    <td>@Html.DisplayFor(modelItem => item.Telefone)</td>
                                    <td>@Html.DisplayFor(modelItem => item.Ncont)</td>
                                    <td style="display:inline-flex">
                                        <a class="btn btn-outline-info" name="Modificar" href="Clientes/Update/@item.Id"><i class="glyphicon glyphicon-edit"></i></a>
                                        <a class="btn btn-outline-danger" style="color:red" name="Apagar" href="" onclick="Delete('@item.Id')"><i class="glyphicon glyphicon-trash"></i></a>
                                    </td>
                                </tr>
                            }
                    </table>
                    <br />
                    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>

            </div>
            <!-- /.box-body -->
        </div>
        <!-- /.box -->
    </div>
    <!-- /.col -->
    </div>
    <!-- /.row -->
</section>

Мой контроллер:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using AdminPanel_V1.Models;
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
using PagedList;


namespace AdminPanel_V1.Controllers
{
    public class ClientesController : Controller
    {
        DeveloperContext db = new DeveloperContext();

        public ViewResult Index(string sortOrder, string currentFilter, string searchString, int? page)
        {
            ViewBag.CurrentSort = sortOrder;
            ViewBag.NameSortParm = string.IsNullOrEmpty(sortOrder) ? "name_desc" : "";

            if (searchString != null)
            {
                page = 1;
            }
            else
            {
                searchString = currentFilter;
            }

            ViewBag.CurrentFilter = searchString;

            var clientes = from s in db.Cl orderby s.No select s;

            if (!string.IsNullOrEmpty(searchString))
            {
                //clientes = clientes.Where(s => s.Nome.Contains(searchString) || s.Email.Contains(searchString));
            }
            switch (sortOrder)
            {
                case "Id":
                    clientes = clientes.OrderByDescending(s => s.No);
                    break;
                case "Nome":
                    clientes = clientes.OrderByDescending(s => s.Nome);
                    break;
                case "Email":
                    clientes = clientes.OrderBy(s => s.Email);
                    break;
                case "Telefone":
                    clientes = clientes.OrderByDescending(s => s.Telefone);
                    break;
                case "Número de Contribuinte":
                    clientes = clientes.OrderByDescending(s => s.Ncont);
                    break;
                default:
                    clientes = clientes.OrderBy(s => s.Nome);
                    break;
            }

            int pageSize = 20;
            int pageNumber = (page ?? 1);

            return View(clientes.ToPagedList(pageNumber, pageSize));
        }


...