I am using RazorEngine for email templating. I have introduced Take() method into the template. I did this so the authors can dictate how many records they want without us having to change any C# in our code directly. I have tried adding the using statements to the template itself as well as using the fluent configuration and adding the namespaces needed but I am not having any luck.
Error:
'System.Collections.Generic.List<object>' does not contain a definition for 'Take'
Here is my fluent configuration for RazorEngine:
var config = new FluentTemplateServiceConfiguration(c =>
c.IncludeNamespaces(
"System",
"System.Linq",
"System.Collections",
"System.Collections.Generic"));
using (var service = new TemplateService(config))
{
//Razor.SetTemplateService(service);
dynamic dyModel = model;
var parsed = string.IsNullOrEmpty(cacheName)
? service.Parse(template, dyModel,null, cacheName)
: service.Parse(template, dyModel,null,null);
return parsed;
}
If I purposely state a namespace incorrectly, I do get an error saying it couldn't find it so I know that it is processing the config data but despite that, I am still getting the error.
Any ideas on what I am doing wrong? I am passing in a dynamic model which either is a List or has a List on it.
因此,这有点la脚,RazorEngine的Wiki上有一张票证指出该问题已得到修复,所以我使用错了或者没有得到修复,但这是我要做的才能使其在razor文件中工作。
var topFive = ((List<dynamic>) Model.MyList).Take(5);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.