List does not contain a definition for 'ToPagedList'

↘锁芯ラ 提交于 2019-12-01 14:24:02

First of all don't use ToList()! If you have like 10.000 records in database it will first load them to memory and then execute method ToPagedList

If you look in pagedlist extensions definition then you will see that you can also use iqueryable

    // Summary:
    //     Creates a subset of this collection of objects that can be individually accessed
    //     by index and containing metadata about the collection of objects the subset
    //     was created from.
    //
    // Parameters:
    //   superset:
    //     The collection of objects to be divided into subsets. If the collection implements
    //     System.Linq.IQueryable<T>, it will be treated as such.
    //
    //   pageNumber:
    //     The one-based index of the subset of objects to be contained by this instance.
    //
    //   pageSize:
    //     The maximum size of any individual subset.
    //
    // Type parameters:
    //   T:
    //     The type of object the collection should contain.
    //
    // Returns:
    //     A subset of this collection of objects that can be individually accessed
    //     by index and containing metadata about the collection of objects the subset
    //     was created from.
public static IPagedList<T> ToPagedList<T>(this IQueryable<T> superset, int pageNumber, int pageSize);

About yours problem, check if you have referenced pagedlist and pagedlist.mvc. Also try rebuild project and check if any other errors are shown

You're probably missing a "using xxxxxx" namespace.

using PagedList;

These are usually "extension methods"......and while they extend something that you probably already have a "using" statement for...the extension method itself is probably in another namespace (thus requires an additional "using" statement).

APPEND

You mention "I tried deleting and adding PagedList again via Package Manager Console"

When you do this, there is a drop down box for the target project. Make sure you have the correct csproj listed in the drop down box.

To make super sure you have the reference, open up your proj file (csproj) in notepad or notepad++ and look for the reference.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!