RazorLight
RazorLight copied to clipboard
TemplateCompilationException: Cannot use a lambda expression - .Net Core 2.0
For note,
This following Template which contains Lambda Expression, throws TemplateCompilationException in RazorLight version 2.0.0-alpha3 at method CompileRenderAsync.
Template:
@(@Model.Items?.Sum(p => p?.Quantity))
Exception:
RazorLight.TemplateCompilationException: 'Failed to compile generated Razor template:
- (0:24) Cannot use a lambda expression as an argument to a dynamically dispatched operation without first casting it to a delegate or expression tree type.
Solved by declaring explicit Model Type in Template, making sure the Template is not Rendered as Dynamic.
@model MyProject.MyModel
Thanks
I have this problem.
But my model is dynamic. i can not do the same solution