views:

179

answers:

2

Hi everyone, I am using jquery ajax method in my app and from the web method I am returning a huge generic list.Upon jquery ajax success I am rendering div's with the data retruned from the web method. B'coz the data returned is very huge,I need to paginate the results.Initially I am returning the first 10 records using List.Take(10).Then upon the next pages button clicks I do not understand how to return the next records.

Could someone please help?

A: 

Use the Skip method to skip records to the appropriate page. For example:

List.Skip(n).Take(10) 

You'll probably need some bounds checking for the size of the list but that's not very difficult.

David in Dakota
Thanks David,I am able to get the next records with List.Skip(n).Take(10). Basically I have a div with buttons for page numbers and upon clicking on any of the buttons I want to make a async request to the server and get the results.so upon clicking on any of these page numbers I want to invoke the same Jquery ajax method,passing name of the button clicked.Is that possible?
kranthi
It's possible, I would recommend studying the following Phil Hack blog post as well as the sample projects he makes available.http://haacked.com/archive/2009/04/14/using-jquery-grid-with-asp.net-mvc.aspx
David in Dakota
A: 

Why returning huge data and paginate whith js. Its better for performance to get only the data that you have in your grid.

For page1 display 1-10 For page2 display 11-20 etc

The request must contain the page number so SQL the limit you want for each grid page

ntan