I'm really surprise since I can do something like @Model.NestedObject.name in straight MVC3/Razor easily.
It works fine if I just use the Ids (the foreign keys).
Ideas?
View Code:
@Html.Telerik().Grid(Model).Name("MappingGrid").Columns(columns=> { columns.Bound(e=>e.VendorId); columns.Bound(e=>e.ProductId); columns.Bound(e=>e.EdiColumn.EdiColumnName); columns.Bound(e=>e.EdiColumn.EdiColumnName); columns.Bound(e=>e.EdiCanonical.CanonicalName); columns.Bound(e=>e.Description); }).Pageable(paging=>paging.PageSize(50)).Sortable().Filterable()Given Models:
public class EdiCanonical{ [ScaffoldColumn(false)] [Key] public int CanonicalId { get; set; } [DisplayName("Canonical Name")] public string CanonicalName { get; set; }}public class EdiColumn{ [Key] [ScaffoldColumn(false)] public int EdiColumnId { get; set; } [DisplayName("ColumnName")] public string EdiColumnName { get; set; } public string Description { get; set; }}public class EdiColumnCanonical{ [Key] [ScaffoldColumn(false)] public int EdiColumnCanonicalId { get; set; } [DisplayName("Vendor")] public int VendorId { get; set; } [DisplayName("Product")] public int ProductId { get; set; } [DisplayName("Column")] public virtual EdiColumn EdiColumn { get; set; } [DisplayName("Canonical")] public virtual EdiCanonical EdiCanonical { get; set; } [DisplayName("Description")] public string Description {get;set;}}7 Answers, 1 is accepted
This is a very strange problem as the grid fully supports binding to nested object properties. In this demo for example we have the following column definition:
columns.Bound(o => o.Customer.ContactName).Width(200);When is the "Invalid Column Name" error generated? Can you show how your models look like? Regards,
Atanas Korchev
the Telerik team
The error occurs right when generating the view.
Thanks!
Cam
We would probably need the underlying database tables in order to reproduce the exact error message. Is there a chance to provide it as well? We can easily make a sample project using dummy data but the error won't appear for obvious reasons.
Regards,Atanas Korchev
the Telerik team
Are you using entity framework code first? If yes please send us the mapping configuration as well.
Regards,Atanas Korchev
the Telerik team
I have included the DbContext/Entities class if that's what you're asking for.
using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Data.Entity;namespace EdiAdmin.Models{ public class EdiEntities:DbContext { public DbSet<EdiCanonical> EdiCanonicals { get; set; } public DbSet<EdiColumn> EdiColumns { get; set; } public DbSet<EdiColumnCanonical> EdiColumnCanonicals{ get; set; } }} I think the problem is not caused by Telerik Grid for ASP.NET MVC. It is rather caused by incomplete mapping configuration. I managed to get the same exception without using the grid at all. I just forced execution of the query:
var model = new EdiDbContext().EdiColumnCanonical;
Find attached my test project.
In order to avoid this exception you need to configure the nested object mappings. Please refer to the Entity Framework documentation for instructions. Greetings,
Atanas Korchev
the Telerik team