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
2009-04-16 13:52:21
Shouldn't the first .Take be .Skip ?
Joel Coehoorn
2009-04-16 13:55:31
@Joel: I had just updated it before your comment, refresh to see.
Mehrdad Afshari
2009-04-16 13:56:11
@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. :-)
2009-04-16 16:57:57
@Jack: What sort of revisions? Total rewrites? I've reported several simple mistakes to him that are fixed in the current revision.
Mehrdad Afshari
2009-04-16 17:07:20
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
2009-11-24 18:59:22
+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
2009-04-16 14:26:02