I am creating MVC3 Site and using pagination (using PagedList;) in that to display bunch of data. I have a stored procedure which gets more than 2000 rows per call.
I have used AJAX with JQUERY to retrieve data ($.ajax call in jquery) and doing pagination on retrieved data in controller. So I am getting back 2000 data rows from a stored procedure and doing pagination on them in the controller and show 10 rows of data. But when I click on “Next” / “previous” links, controller calls the same stored procedure again and retrieves another 2000 rows and in controller based on pagenumber it displays data. So every time it fetches 2000 rows.
I am not using any wrapper class here. Calling stored procedure directly from controller.
Thanks.
You will have to modify the stored procedure so that it takes the current page number and the number of records to return as parameters. This way the pagination will be done directly on the SQL Server which is the only correct way to do pagination if you are concerned about efficiency as it avoids you from fetching all the records from the database and slicing them on the client.