Skip to main content
 首页 » 编程设计

c#之如何对 WebGrid 中的多列进行排序

2024年01月01日47lautakyan007

我在我的 ASP.NET MVC 3 (C#) 应用程序中使用 WebGrid。我想对多列进行排序(就像我们可以在 tablesorter 中做的那样)。

在 WebGrid 中是否可行?如果可以,我该怎么做?

请您参考如下方法:

WebGrid Helper 默认提供排序。

因此,当您编写如下所示的简单实例时,您将默认进行排序和分页:

var myGrid = new WebGrid(Model); 
myGrid.GetHtml(); 

引用自无效链接:

Out of the box, the WebGrid provides these functions by doing Get requests and passing in a few values over the query string. The WebGrid will see these values in the new request, and adjust the output accordingly. This means that the WebGrid expects the entire set of data in each view in order to generate the paging properly.

这意味着对于较大的数据集,您会遇到性能问题,因为您需要将所有数据一次拉入内存,以便 Helper 正确计算分页和排序指标。