Organizational Research By

Surprising Reserch Topic

paging search results with asp net mvc

paging search results with asp net mvc  using -',,pagination,paging'

I have a situation that I couldn't find a solution for through my searches on here. Here is the scenario:

I have a search form with 2 required fields and multiple optional ones. The form posts to an action method that determines which fields are selected and builds a List<> of objects that match the search criteria. I then pass that List<> to the view for display.

This issue I am running into involves how paging is typically done with mvc. For past projects I have used a custom Html helper that creates links which include the query parameters as well as a "page" parameter. It then uses a GET request and the .Take().Skip() format.

I've hit a wall on this project as I can't use a GET request for the search criteria and I can't figure out a way to keep the List<> in memory to do the usual "page" parameter trick.

I thought about storing the List<> in the session but the objects and the list could be very large.

I would think this is a popular issue with advanced search forms but I can't seem to find a good solution. Any help would be appreciated. Thanks!

asked Oct 19, 2015 by rajeshujade
0 votes

Related Hot Questions

3 Answers

0 votes

How about cacheing the search result object and giving it a unique key. You would then have your paging links reference that unique (SearchID) and have your action look for that object, pull it from cache and Skip/Take from there.

This will not rebuild the object for every request, making page loading much faster and reducing strain on your database/application.

Here is a article about cacheing:

Here is a video about cacheing:

Note: Be sure you specify expiration date on the cached object.

answered Oct 19, 2015 by okesh.badhiye
0 votes

If I understand properly, you only want to load the search results one time, and then page through them.

Have you looked into any jQuery paging functionality? You can just dump the entire list to the page and use JavaScript to handle the paging (and sorting if you like).

An example can be found at

answered Oct 19, 2015 by android_master
0 votes

Put everything in the same form: the required fields, the optional fields, the page links.

Two possibilities:

  1. Use submit buttons or images instead of anchor tags for the page links each having a different name (e.g. page1, page2, ...): this will allow you to get the desired page when the form is submitted.
  2. Put a hidden field inside your form. Then add a javascript click handler to any of the page anchors. This handler will update the value of the hidden field with the page, submit the form and cancel the event.

So clicking on any of the pager links will submit the form with all the data you need to build the list and pager links.

answered Oct 19, 2015 by r3tt