I'm using RazorEngine in a templating solution. I have to use anonymous objects for my model data. The code:
string template = @"
Name: @Model.name
@foreach(var person in @Model.People) {
<row>
<column header=""Name"" width=""5cm"">@person.Name</column>
<column header=""Age"" width=""5cm"">@person.Age</column>
</row>
}";
var personList = new List<object>();
personList.Add(new { Name = "Bob", Age = 25 });
personList.Add(new { Name = "Peter", Age = 30 });
var model = new { name = "Henry", People = personList };
string result = Razor.Parse(template, model);
I'm getting an RuntimeBinderException ('object' does not contain a definition for 'Name').
Can anyone help me?
Thank you!