This is a migrated thread and some comments may be shown as answers.

Kendo MVC Grid ICollection Count

0 Answers 154 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Chad England
Top achievements
Rank 1
Chad England asked on 01 Aug 2012, 02:24 PM
Using MVC and Entity Framework I have a model that looks like this:

 public class AddressType
    {
        [ScaffoldColumn(false)]
        public int AddressTypeId { get; set; }
        [Display(Name = "Address Type", Prompt = "Select an Address Type")]
        [Required(ErrorMessage = "Please Select an Address Type.")]
        public string AddressTypeName { get; set; }
        [Display(Name = "Order", Prompt = "Select a display order")]
        [Required(ErrorMessage = "Please Select a display order.")]
        [Range(0, 10000)]
        public int DisplayOrder { get; set; }
        public DateTime? DateCreated { get; set; }
        public string CreatedBy { get; set; }
        public DateTime? DateModified { get; set; }
        public string ModifiedBy { get; set; }
        public byte[] RowVersion { get; set; }
        [Display(Name = "Address")]
        public virtual ICollection<Address> Addresses { get; set; }
    }

Normally in MVC I can do the following
<td>
@(item.Addresses == null ? "None" : item.Addresses.Count.ToString())
</td>


Currently my Grid code looks like this, so far I am having no luck getting the count to display for Addresses

@(Html.Kendo().Grid(Model)    
    .Name("Grid")
    .Columns(columns => {
        columns.Bound(p => p.AddressTypeName);
        columns.Bound(p => p.DisplayOrder);
        columns.Bound(p => p.Addresses);
        columns.Command(command => { command.Edit(); command.Destroy(); });
    })
    .ToolBar(toolbar => toolbar.Create())
    .Editable(editable => editable.Mode(GridEditMode.PopUp))
    .Pageable()
    .Sortable()
    .Scrollable()
    .DataSource(dataSource => dataSource
        .Server()
        .PageSize(5)
        .Model(model => {
            model.Id(p => p.AddressTypeId);
            model.Field(p => p.Addresses).Editable(false);
        })
        .Aggregates(aggregates =>
    {
        aggregates.Add(p => p.Addresses).Count().ToString();
    })
        .Read("Index", "AddressType")
        .Update("Edit", "AddressType")
        .Create("Create", "AddressType")
        .Destroy("Delete", "AddressType")
    )
)

No answers yet. Maybe you can help?

Tags
Grid
Asked by
Chad England
Top achievements
Rank 1
Share this question
or