views:

192

answers:

3

I was run across issue to paging my list object in asp.net mvc where my object is simply load by LINQ-to-SQL.

Is it some kinds of will_paginates command?

in rails, i can do like

Users.paginate(:all, :page => 1, :page_size => 20)
+4  A: 

In Linq this would be

Users.Skip(pageSize*page).Take(pageSize)

This would assume zero based counting.

spender
+4  A: 

Check out - http://pagedlist.codeplex.com/

Will create an extension method ToPagedList which can be used like so:

 using PagedList;

 var firstPage = list.ToPagedList(0, 20); // first page, page size = 20

 Console.WriteLine("Is first page? {0}", firstPage.IsFirstPage); // true
 Console.WriteLine("Is last page? {0}", firstPage.IsLastPage); // false
 Console.WriteLine("First value on page? {0}", firstPage[0]); // 1
 Console.WriteLine();
CVertex
I'm astonished that they've managed to make a 168k (zipped) mountain out of this molehill!
spender
Before you criticize, you should consider that your proposed solution will perform poorly on the first (and thus most commonly requested) page (see http://blogs.teamb.com/craigstuntz/2009/06/10/38313/), offers no pagination (paging button) features in the view, and must be re-implemented everywhere it is used.
Craig Stuntz
To be clear, my comments are directed to spender, not CVertex.
Craig Stuntz
Yep. I suppose there is more to it than meets the eye!
spender
Troy
+2  A: 

No there is not, but you should check out this blog post by Rob Conery that shows you a good way to implement it. http://blog.wekeroad.com/blog/aspnet-mvc-pagedlistt/

Robban
I really liked Rob's code (actually it was ScottGu's code that Rob posted, but I digress), in fact I'm the maintainer of an enhanced version of it:http://pagedlist.codeplex.com/
Troy