Using version 2011.2 trying to bind to a property of a child object using the MVC helper...
...Columns(x => { x.For(y => y.Script.Name).Width("auto").HeaderText("Script Name");...})
Fails because the key is set to just "Name" which doesn't exist on y. I tried forcing the Key to "Script.Name", but that didn't help.
Do I have to make a flat view model?
Hi wpbrown,
What are you trying to acheive with y.Script.Name?
What is expected in tha lambda expression is the key correcponding to your model. So if that's your child layout and you have set correclty Primary Key and Foreign Key properties, this ScriptName property should be part of your model.
Can you send us your sample, to provide you more correct information which will help you?
Thanks,
I have JSON data like so returned....
{ "Metadata" : { "timezoneOffset" : -18000000 }, "Records" : [ { "Agent" : null, "AgentId" : 3, "Completed" : "/Date(1336599104000)/", "DurationSec" : 17, "Id" : 146, "Script" : { "Id" : 4, "Name" : "Test Script 1", "Profile" : null, "Transactions" : null }, "ScriptId" : 4, "Status" : 1 }, ... more records...
In terms of the model described by Georgi above, in the view I have...
@(Html.Infragistics().Grid<MyClass>().ID("runsGrid") .Columns(x => { x.For(y => y.Completed).Width("15%").HeaderText("Date").Format("yyyy-MM-dd HH:mm"); x.For(y => y.Status).Width("8%").HeaderText("Status"); x.For(y => y.Script.Name).Width("auto").HeaderText("Script Name"); }) .DataSourceUrl(Url.Action("RunData", new { id = Model.Agent.Id })) .DataBind().Render())
I get an error that Name is not found.
Hi,
Complex properties in the Models aren't supported yet. You would need to bind to a collection of objects, which are of some type X where all properties are simple (such as strings, numbers ,dates, etc.).
We are planning to add support for this in the near future. In the meantime, you can workaround this by creating a new class which flattens your existing one.
Hope it helps. Thanks,
Angel
Hi Angel,
You mentioned that: "Complex properties in the Models aren't supported yet... We are planning to add support for this in the near future.". I was just curious; is this functionality is planned for a specific release? Is this functionality that we can expect in 2013?
Paul
So I flattened my model by using a .Select(x => new FooViewModel { ScriptName = x.Script.Name ... }) in the DataSource query to get the grid to work. However, filtering doesn't work because it doesn't recognize the columns. Is there a work around for filtering too? I don't see how this is supposed to work for all but the simplest, fully denormalized entity models.
Ok. I'm not sure how I can translate the model class to a new class and still provide an IQueryable. Trying to use select to translate to the a new class will cause an exception: failed to translate linq expresssion.
I was able to flatten the JSON by selecting to an anonymous type in Entity Query like
.Select(x=> new { Name = x.Script.Name ....