RazorEngine
RazorEngine copied to clipboard
Support Linq + Anonymous or Dynamic Types
var model = new
{
Name = "John Doe",
Items = new List<dynamic>
{
new
{
Value = 10
},
new
{
Value = 20
}
}
};
string content = @"
@using System.Linq;
@using System.Collections.Generic;
@{
var h = @Model.Items.Sum(p => p.Value);
}
";
Engine.Razor.RunCompile(content, "templateKey", null, model);
Error: You can not use a lambda expression as an argument to a dynamically issued operation without first converting it to a delegate or an expression tree type
I don't think this is currently possible to do at all.
I'm also sad, that LINQ isn't possible in CSHTML files.