tags:

views:

645

answers:

2

I cannot get the pager to work for my ListUsers page. The method in my controller looks like:

public ActionResult ListUsers(int? page, int? pageSize) {   
 int totalItems;
 var members = Membership.GetAllUsers(page ?? 1, pageSize ?? 50, out totalItems);
 ViewData["Users"] = ToList<MembershipUser>(members);
 return View();
}

And my aspx page has the following looks like:

<% var users = ViewData["Users"] as List<MembershipUser>; %>

<% foreach( var user in users ){ %>
        Email is: <%= user.Email %>
<% } %>

<%= Html.Pager((IPagination)ViewData["Users"])%>

I get the error

"Unable to cast object of type 'System.Collections.Generic.List`1[System.Web.Security.MembershipUser]' to type 'MvcContrib.Pagination.IPagination'."

What am I doing wrong?

+2  A: 

You can't pass a list to Html.Pager. You have to pass something that implements IPagination. You can build your own class, or you can create the LazyPagination class -- very easily through the .AsPagination() extension method.

See, e.g, http://davidhayden.com/blog/dave/archive/2009/06/25/MvcContribGridPagerHelpers.aspx

James S
A: 
robnardo