绑定列需要ASP.NET MVC中的字段或属性访问表达式

时间:2014-09-28 17:13:11

标签: c# asp.net-mvc telerik

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

我的代码:

在视图中:

  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;

在交付中,我有任何无效。

问题在哪里?

1 个答案:

答案 0 :(得分:8)

columns.Bound只接受原语为int或string。 您不能聚合或转换对象作为示例:

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

您可以在Deliveries对象中创建一个参数:

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

所以你可以在网格上绑定它。