绑定列需要ASP.NET MVC中的字段或属性访问表达式 [英] Bound columns require a field or property access expression in ASP.NET MVC

查看:95
本文介绍了绑定列需要ASP.NET MVC中的字段或属性访问表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在数据库中有一对多的关系(我使用实体接口在2个obj之间生成关联) 我收到错误消息: 绑定的列需要一个字段或属性访问表达式

I have relations one to many in DB ( i used entity interface to generate associations between 2 obj) Im getting error: Bound columns require a field or property access expression

我的代码:

视图中:

  Html.Telerik()
        .Grid<Y.Orders.Models.Orders>("orders")

        .Name("Orders")
        .DataKeys(dataKeys => dataKeys.Add(o => o.Id))
        //.Pageable(paging => paging.PageSize(20).Style(GridPagerStyles.PageSizeDropDown | GridPagerStyles.NextPreviousAndNumeric))
        .Columns(columns =>
        {
            columns.Command(commands =>
            {
                commands.Custom("comments").ButtonType(GridButtonType.Text).Text("Szczegóły").Action("Index", "Komentarze");
            });
            columns.Bound(o => o.Tytul).Title("Title");
            columns.Bound(o => o.Deliveries.Sum(m=>m.deliveryTime)).Title("Time of order");
        })
        .Filterable()
        .Sortable(sort =>
        {
            sort.SortMode(GridSortMode.MultipleColumn); sort.OrderBy(ord =>
            {
                ord.Add(o => o.Time).Descending();

            });
        })
        .Groupable(grouping => grouping.Groups(groups =>
        {
            groups.Add(c => c.Users.Firms.Name);
        }))
        .Render();

在实体模型中:

    public ObjectSet<Deliveries>  Deliveries
    {
        get
        {
            if ((_ Deliveries
 == null))
                {
                    _Deliveries = base.CreateObjectSet<Deliveries>("Deliveries");
                }
                return _Deliveries;
            }
        }
        private ObjectSet<Deliveries> _Deliveries;

在交货时,我没有任何空值.

In deliveries i havnt any null.

哪里有问题?

推荐答案

列.Bound只接受基本类型为int或string的字符串. 您不能像示例那样聚合或变换对象:

columns.Bound accept only primitive as int or string. You can't aggregate or transform object as your example :

o.Deliveries.Sum(m=>m.deliveryTime)

您确实在Deliveries对象中创建了这样的参数:

You do create in Deliveries object a parameter as this :

public int SumDeliveries 
{
  get { return this.Sum(m=>m.deliveryTime); }
}

,因此您可以将其绑定到网格上.

and so you can bind this on grid.

这篇关于绑定列需要ASP.NET MVC中的字段或属性访问表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆