tags:

views:

109

answers:

2

Hi Friends, Being new to ASP.NET MVC, I would like to know the easy method of paging. The data is IQueryable type.

+2  A: 
var dataPage = data.Skip(pageNumber * pageSize - pageSize).Take(pageSize);

To learn the basic tricks of ASP.NET MVC, I suggest reading the free Professional ASP.NET MVC 1.0 Book Chapter 1 by Scott Guthrie

Mehrdad Afshari
Shouldn't the first .Take be .Skip ?
Joel Coehoorn
@Joel: I had just updated it before your comment, refresh to see.
Mehrdad Afshari
@Mehrdad: I spoke with Scott (author of that chapter/book) and he is working on several revisions that will go into the actual book, so I highly recommend buying it, if it's within your means. :-)
@Jack: What sort of revisions? Total rewrites? I've reported several simple mistakes to him that are fixed in the current revision.
Mehrdad Afshari
Note that Skip(0) is not free. http://blogs.teamb.com/craigstuntz/2009/06/10/38313/ Hence this incurs a performance penalty for the first (and most commonly requested) page in both EF and L2S 4.0.
Craig Stuntz
+4  A: 

I've been using this PagedList type, originally developed by Rob Conery, and enhanced by Troy Goode. I've even written extension methods which make it work with jqGrid. For sheer ease of use, I don't think you're going to beat it.

Craig Stuntz