RazorEngine icon indicating copy to clipboard operation
RazorEngine copied to clipboard

Support Linq + Anonymous or Dynamic Types

Open williamwmd opened this issue 9 years ago • 2 comments

            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

williamwmd avatar Feb 10 '17 11:02 williamwmd

I don't think this is currently possible to do at all.

ghost avatar Feb 10 '17 23:02 ghost

I'm also sad, that LINQ isn't possible in CSHTML files.

Beautyod avatar Mar 06 '17 16:03 Beautyod