ASP.net MVC3 Webgrid
本文关键字:Webgrid MVC3 net ASP | 更新日期: 2023-09-27 18:08:35
我正在使用webgrid来显示一些动态数据。我最近重构了我的代码,从包含各种不同类型的数据在视图中显示的层次模型转移到使用ViewBag。
以前网格会对列进行排序,只是点击标题,但是由于我更改为ViewBag,我的表不排序。我的新代码如下:
@if (ViewBag.data != null)
{
var grid = new WebGrid(
source: ViewBag.data,
defaultSort: "StudyName",
rowsPerPage: 10,
canSort: true,
canPage: true,
ajaxUpdateContainerId: "tableDiv"
);
@grid.GetHtml(
tableStyle: "resultTable",
columns: grid.Columns(
ViewBag.columns)
)
}
有人有什么想法吗?
谢谢。
确保您已将ViewBag.columns
的CanSort
属性设置为true
:
ViewBag.columns = new[]
{
new WebGridColumn
{
ColumnName = "Id"
},
new WebGridColumn
{
CanSort = true,
ColumnName = "StudyName"
},
};
只有设置了此属性的列才会在网格标题中显示为超链接,允许用户对其进行排序。