开发者

Paging search results with asp.net MVC

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 开发者_如何学Cform 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 asp.net 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!


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:

https://web.archive.org/web/20211020111559/https://aspnet.4guysfromrolla.com/articles/100902-1.aspx

Here is a video about cacheing:

http://www.asp.net/learn/Videos/video-6206.aspx

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


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 http://beckelman.net/demos/jqueryTableSorterConPaging/default.aspx


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜