使用 asp.net MVC 对搜索结果进行分页

发布于 2024-08-09 06:17:01 字数 465 浏览 7 评论 0原文

我遇到了一种情况,通过此处的搜索找不到解决方案。场景如下:

我有一个搜索表单,其中包含 2 个必填字段和多个可选字段。该表单发送到一个操作方法,该方法确定选择哪些字段并构建一个 List<> 列表。与搜索条件匹配的对象。然后我传递该 List<>到视图进行显示。

我遇到的这个问题涉及到如何使用 ASP.NET MVC 完成分页。对于过去的项目,我使用了自定义 Html 帮助器来创建包含查询参数以及“页面”参数的链接。然后它使用 GET 请求和 .Take().Skip() 格式。

我在这个项目上遇到了困难,因为我无法使用 GET 请求作为搜索条件,并且我无法找到一种方法来保持 List<>在内存中执行通常的“页面”参数技巧。

我考虑过存储 List<>在会话中,但对象和列表可能非常大。

我认为这是高级搜索表单的一个常见问题,但我似乎找不到好的解决方案。任何帮助将不胜感激。谢谢!

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 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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

终止放荡 2024-08-16 06:17:01

如何缓存搜索结果对象并给它一个唯一的键。然后,您可以让分页链接引用该唯一的 (SearchID),并让您的操作查找该对象,将其从缓存中拉出,然后从那里跳过/获取。

这不会为每个请求重建对象,从而使页面加载速度更快并减少数据库/应用程序的压力。

这是一篇关于缓存的文章:

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

这是一个有关缓存的视频:

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

注意:确保指定缓存对象的到期日期。

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.

小鸟爱天空丶 2024-08-16 06:17:01

如果我理解正确的话,您只想加载一次搜索结果,然后逐页浏览它们。

您研究过 jQuery 分页功能吗?您可以将整个列表转储到页面并使用 JavaScript 来处理分页(如果您愿意,还可以进行排序)。

可以在以下位置找到示例: http://beckelman.net/demos/jqueryTableSorterConPaging/default.aspx< /a>

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

神经大条 2024-08-16 06:17:01

将所有内容放在相同的形式中:必填字段、可选字段、页面链接。

两种可能性:

  1. 使用提交按钮或图像而不是每个具有不同名称的页面链接的锚标记(例如 page1page2 ...):这将允许您提交表单时获取所需的页面。
  2. 在表单中放置一个隐藏字段。然后将 JavaScript 单击处理程序添加到任意页面锚点。该处理程序将更新页面隐藏字段的值,提交表单并取消事件。

因此,单击任何寻呼机链接都会提交表单,其中包含构建列表和寻呼机链接所需的所有数据。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文