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

本文关键字:字段 属性 访问 表达式 访问表 ASP MVC NET 绑定 | 更新日期: 2023-09-27 18:25:01

我在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;

交货时我没有任何空货。

问题出在哪里?

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

columns.Bound只接受作为int或字符串的基元。您不能像您的示例那样聚合或转换对象:

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

您确实在Deliveries对象中创建了一个参数,如下所示:

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

所以你可以把它绑定到网格上。