Bound columns require a field or property access expression in ASP.NET MVC

家住魔仙堡 提交于 2019-12-12 09:23:45

问题


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

My code:

in view:

  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();

in entity model:

    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.

Where is problem ?


回答1:


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)

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.



来源:https://stackoverflow.com/questions/26087421/bound-columns-require-a-field-or-property-access-expression-in-asp-net-mvc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!