Working with PagedList and Membership

2019-07-13 18:00发布

问题:

I've been playing around with Troy Goode's PagedList http://pagedlist.codeplex.com/. I was wondering if anyone has gotten it to work with the built in asp.net Membership piece?

I have over 8000 users so I need to be able to page thru the User list.

using a line like this in my memberhsip controller doesn't work. It wont compile.

Membership.GetAllUsers().ToPagedList(currentPageIndex, defaultPageSize);

Appreciate any guidance in this area...

TIA

-MARK- putrtek@gmail.com

回答1:

Membership.GetAllUsers() returns an instance of type MembershipUserCollection. That type does not implement IEnumerable or IQueryable. ToPagedList is a collection of extension methods overloaded for IEnumerable and IQueryable. In order to use it, therefore, you need to transform the membership user collection into one of those types. In the IDE, I concede that there is an AsEnumerable method. You might have to add using System.Linq to use it, though. So try:

Membership.GetAllUsers().AsQueryable().ToPagedList(currentPageIndex, defaultPageSize);

However, GetAllUsers() is already overloaded to do paging, so you should do this instead:

Membership.GetAllUsers(currentPageIndex, defaultPageSize, out totalRecords);