mardi 30 avril 2019

Paged list says it does not contain a definition for PagedListPager

When trying to create a Paged ListPager under my Table I get the following error:

'IHtmlHelper<IPagedList<Partnership>>' does not contain a definition for 'PagedListPager'

I have the proper imports as far as I can see so i am not sure what is wrong. Here is my view:

@using PagedList.Mvc;
@using PagedList;
@model IPagedList<Partnership>

@{
    ViewData["Title"] = "Search";
}
<h2>Search</h2>

<p>
    <a asp-action="Create">Create New</a>
</p>
<table class="table">
    <thead>
        <tr>
            <th>
                Organzation
            </th>
        </tr>
    </thead>
    <tbody>
        @foreach (var partnership in Model)
        {
            <tr>
                <td>
                    @Html.DisplayFor(modelItem => partnership.OrganizationName)
                </td>
            </tr>
        }
    </tbody>
</table>
    @Html.PagedListPager(Model, page => Url.Action("Search", new { page }));

Here is my Controller:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using PACE.Models;
using PagedList;

namespace PACE.Controllers
{
    public class SearchPartnershipsController : Controller
    {
        // GET: SearchPartnerships
        public ActionResult Search(int? page)
        {
            var PaceDB = new Models.PaceDB();
            var Organizations = PaceDB.GetAllOrganization();
            var Partnerships = new List<Partnership>();
            var PartnershipsCount = PaceDB.PartnershipTotal();
            Debug.WriteLine(PartnershipsCount);

            for(int i = 0; i<=PartnershipsCount; i++)
            {
                Partnerships.Add(new Partnership { OrganizationName = Organizations[i] });
            }
            int pageNumber = (page ?? 1);
            return View(Partnerships.ToPagedList(pageNumber,20));
        }
    }
}

Could I be missing a package or using that is a bit more obscure. Most people who have this problem seem to get it solved by adding the two imports I have at the top of my view.




Aucun commentaire:

Enregistrer un commentaire