简体   繁体   English

在ASP.NET MVC中进行排序,筛选和分页

[英]Sorting, Filtering and Paging in ASP.NET MVC

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. 我看到了一些JavaScript网格示例,但是我在谈论的是最适合MVC架构的通用方法。

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. 一方面,我认为如果将逻辑放在路线(项目/页面/排序/)中,我们将获得诸如添加书签和避免使用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. 另一方面,如果我们使用JavaScript网格,则可以在ASP.NET Web表单中具有类似于旧式网格视图的行为。

I find that using HTML helpers may be useful for paging, but have no idea if they are good for sorting or not. 我发现使用HTML帮助程序可能对分页很有用,但是不知道它们是否适合排序。 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. 我看过jQuery, tableSorter快速搜索插件,但它们仅适用于当前获取的数据,不会帮助进行可能需要接触数据库的实际排序和过滤。 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. 对于将这些工具与AJAX并用,我有一些想法,但是我不知道是否在任何地方都做了类似的工作。

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. 我研究过的另一种方法是在Web表单上使用动态数据,但是我没有发现关于将MVC和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. 我知道为单个案例实现过滤和排序很简单(尽管它有一些问题,例如使用Dynamic LINQ,这还不是一种标准方法),但是我创建一个在所有情况下都可以使用的排序或过滤工具寻找。 (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表单开发人员想知道为什么每次我想为不同的实体实现排序方案时,为什么要编写相同的代码时,我都希望掌握一些东西)。

Here's my solution based on jqGrid: http://sprokhorenko.blogspot.com/2010/01/jqgrid-mvc-new-version-sources.html 这是我基于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. 它是S#arp Architecture和NHibernate特有的,所以我不确定它是否适合您的需求。 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: 基本上,它只是具有所有优点和缺点的jqGrid,但已集成到MVC中:

  1. control all formatting and editing with attributes on ViewModel 使用ViewModel上的属性控制所有格式和编辑
  2. automatic requests, sorting/filtering/paging handling 自动请求,排序/过滤/分页处理
  3. automatic CRUD handling 自动CRUD处理
  4. Can handle both DB and list based repositories 可以处理基于数据库和基于列表的存储库
  5. no bookmarkable routes/links... 没有可收藏的路线/链接...

All you need is to provide ViewModel with attribute and override couple of template CRUD methods (can be as little as just InternalConstructEntity(). 您所需要做的就是为ViewModel提供属性,并覆盖几个模板CRUD方法(可以与InternalConstructEntity()一样少。

You could check out MVContrib, they have pretty good grid support. 您可以查看MVContrib,它们具有很好的网格支持。 http://www.codeplex.com/MVCContrib http://www.codeplex.com/MVCContrib

For LOB Applications the Telerik Controls might be a good solution. 对于LOB应用程序,Telerik控件可能是一个很好的解决方案。

I personally use jQuery DataTables . 我个人使用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 . 我已经用C#和MVC为jQuery DataTables编写了一个插件 It uses the standard jQuery DataTables request and manipulates an IQeryable instance accordingly. 它使用标准的jQuery DataTables请求并相应地处理IQeryable实例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM