与asp.net MVC分页的搜索结果 [英] 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:
我有2必填字段,多个可选的人一个搜索表单。形式职位,以决定哪些字段选择并构建一个列表℃的操作方法;>符合搜索条件的对象。然后,我传递名单<>为显示视图
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.
这个问题我遇到涉及如何分页通常与asp.net的MVC实现。对于过去的项目我已经使用它创建的链接,其中包括查询参数,以及一个页参数的自定义HTML帮手。然后,它使用一个GET请求和。取()跳过()格式。
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.
我已经打了一堵墙在这个项目上,我无法使用搜索条件的GET请求,我不能想出一个办法来保持列表&LT招。
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.
我想过存储列表&LT;>的会议,但对象和列表可能是非常大的。
I thought about storing the List<> in the session but the objects and the list could be very large.
我认为这是一个普遍的问题,具有先进的搜索形式,但我似乎无法找到一个很好的解决方案。任何帮助将是AP preciated。谢谢!
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!
推荐答案
如何cacheing搜索结果对象,并给它一个唯一的密钥。那么你将有你的分页链接引用该唯一的(SearchID),并有你的行动看该对象,从缓存中把它和跳过/从那里。
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.
下面是关于cacheing文章:
Here is a article about cacheing:
http://aspnet.4guysfromrolla.com/articles/100902-1.aspx
下面是关于cacheing视频:
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.
这篇关于与asp.net MVC分页的搜索结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!