Rop*_*tah 6 .net razor razorengine
我在非MVC环境中使用Razor Engine(razorengine.codeplex.com).我编译存储在文件中的模板,@inherits用于智能感知支持.
View<>和设置View<>为基类所有cshtml文件都有以下@inherits指令:
@inherits View<SomeModel>
Run Code Online (Sandbox Code Playgroud)
抛出错误:
找不到命名空间View的类型,是否缺少程序集引用?
我的web.config包含以下条目:
<add namespace="CustomAssembly.NamespaceContainingViewClass" />
Run Code Online (Sandbox Code Playgroud)
我认为这与其他条目有关<assemblies>,我CustomAssembly没有提到.是这样的吗?我可以使用另一个程序集中包含的自定义基类进行编译吗?
ps我无法检索程序集的强名称,因为我的自定义程序集引用了一个没有强名称的3d方程序集...
堆栈跟踪:
at RazorEngine.Compilation.DirectCompilerServiceBase.CompileType(TypeContext context)
at RazorEngine.Templating.TemplateService.CreateTemplate(String template, Type modelType)
at RazorEngine.Templating.TemplateService.GetTemplate(String template, Type modelType, String name)
at RazorEngine.Templating.TemplateService.Compile(String template, Type modelType, String name)
at RazorEngine.Razor.Compile(String template, Type modelType, String name)
Run Code Online (Sandbox Code Playgroud)
您可以在TemplateServiceConfiguration中添加名称空间:
TemplateServiceConfiguration templateConfig = new TemplateServiceConfiguration();
templateConfig.Namespaces.Add("MyNamespaceGoesHere");
templateConfig.Resolver = new DelegateTemplateResolver(name =>
{
<My template resolve implementation>
}
Razor.SetTemplateService(new TemplateService(templateConfig));
using (TextWriter tw = new StringWriter())
{
Razor.Resolve(viewName + ".cshtml", model).Run(new ExecuteContext(), tw);
var emailHtmlBody = tw.ToString();
}
Run Code Online (Sandbox Code Playgroud)
您可能需要将 razor 配置部分添加到您的web.config:
<?xml version="1.0" encoding="UTF-8" ?>
<configuration>
<configSections>
<section name="razorEngine" type="RazorEngine.Configuration.RazorEngineConfigurationSection, RazorEngine" requirePermission="false" />
</configSections>
</configuration>
<razorEngine>
<namespaces>
<add namespace="CustomAssembly.NamespaceContainingViewClass" />
</namespaces>
</razorEngine>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7166 次 |
| 最近记录: |