ASP.NET MVC 中的排序、过滤和分页
实现这些功能的最佳方法是什么?涉及项目的哪一部分?
我看到了一些 JavaScript 网格的示例,但我谈论的是最适合 MVC 架构的通用方法。
我考虑过配置路由和模型来实现这些功能,但我不清楚这是否是实现这些功能的正确方法。一方面,我认为如果我们将逻辑放入路由(item/page/sort/)中,我们将获得诸如添加书签和避免使用 JavaScript 之类的好处。另一方面,如果我们使用 JavaScript 网格,我们可以拥有像 ASP.NET Web 表单中的老式网格视图那样的行为。
我发现使用 HTML 助手可能对分页有用,但不知道它们是否适合排序。我研究过 jQuery、 tableSorter 和 快速搜索插件,但它们仅适用于当前获取的数据,对于可能需要接触数据库的实际排序和过滤没有帮助。我对将这些工具与 AJAX 结合使用来获得有效的东西有一些想法,但我不知道是否有类似的工作在任何地方进行。
我研究的另一种方法是在 Web 表单上使用动态数据,但我没有找到任何关于集成 MVC 和 DD 是否是个好主意的建议。我知道针对个别情况实现过滤和排序很简单(尽管它存在一些问题,例如使用动态 LINQ,这还不是标准方法),但创建一个适用于所有情况的排序或过滤工具是我的想法寻找。 (也许这是因为当 Web 表单开发人员想知道为什么每次我想为不同实体实现排序场景时我都编写相同的代码时,我希望手头有一些东西)。
What is the best approach to implement these features and which part of project would involved?
I see some example of JavaScript grids, but I'm talking about a general approach which best fits the MVC architecture.
I've considered configuring routes and models to implement these features but I don't have a clear idea that if this is the right approach to implementing such features. On the one hand, I think if we put logic in routes (item/page/sort/), we would have benefits like bookmarking and avoiding JavaScript. On the other hand if we use JavaScript grids, we can have behavior like the old school grid views in ASP.NET web forms.
I find that using HTML helpers may be useful for paging, but have no idea if they are good for sorting or not. I've looked at jQuery, tableSorter and quick search plug-ins, but they work just on the currently-fetched data and won't help in real sorting and filtering that may need to touch the database. I have some thoughts on using these tools side by side with AJAX to get something which works, but I have no idea if there are similar efforts done yet anywhere.
Another approach I looked at was using Dynamic Data on web forms, but I didn't find any suggestions out there as to whether or not it is a good idea to integrate MVC and DD. I know implementing filtering and sorting for an individual case is simple (although it has some issues like using Dynamic LINQ, which is not yet a standard approach), but creating a sorting or filtering tool which works in all cases is the idea I'm looking for. (Maybe this is because I want have something in hand when web form developers are wondering why I'm writing same code each time I want to implement a sort scenario for different Entities).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这是我基于 jqGrid 的解决方案: http://sprokhorenko .blogspot.com/2010/01/jqgrid-mvc-new-version-sources.html
它有点特定于 S#arp 架构和 NHibernate,所以我不确定它是否适合您的需求。但它是模块化的,因此例如很容易调整基本存储库的实现。
基本上它只是 jqGrid 及其所有优点和缺点,但集成到 MVC 中:使用
您所需要的只是为 ViewModel 提供属性并覆盖几个模板 CRUD 方法(可以小至 InternalConstructEntity())。
Here's my solution based on jqGrid: http://sprokhorenko.blogspot.com/2010/01/jqgrid-mvc-new-version-sources.html
It is a bit specific to S#arp Architecture and NHibernate, so I'm not sure if it suits your needs. But it's modular so for example it's easy to tweak base repository implementation.
Basically it's just jqGrid with all its pros and cons but integrated into MVC:
All you need is to provide ViewModel with attribute and override couple of template CRUD methods (can be as little as just InternalConstructEntity().
你可以看看 MVContrib,他们有很好的网格支持。
http://www.codeplex.com/MVCContrib
对于 LOB 应用程序,Telerik Controls 可能是一个不错的解决方案。
You could check out MVContrib, they have pretty good grid support.
http://www.codeplex.com/MVCContrib
For LOB Applications the Telerik Controls might be a good solution.
我个人使用 jQuery DataTables。它非常简单,并且有一个明确定义的服务器端请求。 我写了一个插件用于使用 C# 和 MVC 的 jQuery DataTables。它使用标准 jQuery DataTables 请求并相应地操作 IQeryable 实例。
I personally use jQuery DataTables. It's very simple and has a well-defined server-side request. I've written a plugin for jQuery DataTables with C# and MVC. It uses the standard jQuery DataTables request and manipulates an IQeryable instance accordingly.