toddams/RazorLight

dynamic object support

avoxm opened this issue · 1 comments

avoxm commented

Is there a way to render nested dynamic types.

I have a designer UI that allows a user to specify their own template variables and pass down a json to be injected.

Here's an input :

dynamic templateParams = new { Name = "Joe Doe",
    Address = new { City = "Gotham" }, 
    Products = new[] { new { SKU = 1232143243,  Count= 10 }, new { SKU = 15565,  Count= 15 } }
};

I am failing to get Product item details. Here's the sample view.

model dynamic 
Hi @Model.Name from @Model.Address.City 
Here are your products :
@foreach(var product in Model.Products ) { <text> @product.SKU </text> };

It seems like it coverts the model to object class instance and as a result Amount property is not visible.

Unhandled exception. Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: 'object' does not contain a definition for 'Amount'

Did you try Googling your error?

Second result says:

you can't pass an anonymous type into a dynamically-typed view because the anonymous types are compiled as internal.