MvcContrib 对相关对象进行网格排序
我想使用 MvcContrib Grid 对相关表进行服务器端排序
我有
@Html.Grid(Model.Result).Columns(column =>
{
column.For(u => u.Name).Named("Name");
column.For(u => u.Country.Name).Named("Country").SortColumnName("Country");
}).Sort(Model.GridSortOptions)
这可以正确显示表/网格。但是,我无法按 Country.Name 排序,出现错误
DbSortClause 表达式必须具有可比较顺序的类型
I want to do server side sorting of a related table using MvcContrib Grid
I have
@Html.Grid(Model.Result).Columns(column =>
{
column.For(u => u.Name).Named("Name");
column.For(u => u.Country.Name).Named("Country").SortColumnName("Country");
}).Sort(Model.GridSortOptions)
This displays the table/grid correctly. However I cannot sort by Country.Name I get an error
DbSortClause expressions must have a type that is order comparable
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我做了一些挖掘,看起来 MvcContrib Grid 公开的本机 OrderBy() 方法不支持对子属性上的数据进行排序。
在处理数据呈现和排序的控制器操作中,您需要稍微自定义行为,而不是调用 data = data.OrderBy(sort.Column, sort.Direction) 。在您的情况下,最简单的解决方案可能是专门处理值“Country.Name”,然后对其余可排序列使用默认行为。像这样的东西应该足够了:
I did some digging and it looks like the native OrderBy() method which MvcContrib Grid exposes does not support sorting data on a sub-property.
In the controller action which handles presenting and sorting the data, rather than calling
data = data.OrderBy(sort.Column, sort.Direction)
, you will need to customize the behavior slightly. In your case, the easiest solution would likely be to handle the value "Country.Name" specially, and then use the default behavior for the rest of the sortable columns. Something like this should suffice:我刚刚结束了一项工作。
我向 ViewModel 添加了一个名为“CountryName”的新属性,该属性映射到 Country.Name。这很好用。
所以我的代码现在
是我的 ViewModel
I just ended up doing a work around.
I added a new property to my ViewModel called "CountryName" which maps to Country.Name. This works fine.
So my code is now
And my ViewModel