我在非MVC環境中使用Razor引擎(razorengine.codeplex.com)。我編譯存儲在文件中的模板,並使用@inherits
來提供智能感知支持。RazorEngine - 命名空間導入編譯錯誤
- RazorEngine大會
- 自定義組件 - 引用RazorEngine,包含
View<>
並將View<>
作爲基類 - Web應用程序 - 引用RazorEngine,自定義程序集,包含.cshtml模板文件
所有CSHTML文件有以下指令@inherits
指令:
@inherits View<SomeModel>
將引發錯誤:
類型的命名空間的看法是沒有發現,是否缺少程序集引用?
我的web.config包含以下項:
<add namespace="CustomAssembly.NamespaceContainingViewClass" />
我覺得這是與其他入門<assemblies>
,其中沒有提到我的CustomAssembly
。是這樣嗎?我可以使用另一個程序集中包含的自定義基類進行編譯嗎?
p.s.我不能代表大會取得強大的名字,因爲我的自定義組件引用了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)
此錯誤在哪裏拋出?什麼是堆棧跟蹤? – SLaks 2011-05-16 12:54:17
當我使用參數(其中一個是包含'@ inherits'的模板字符串)調用'Razor.Compile'時,會引發錯誤。我已經添加了堆棧跟蹤到上面的問題。 – Ropstah 2011-05-16 13:10:14
在@inherits之後擁有完全限定的名稱時它工作嗎? MVC可能會做一些額外的工作來使命名空間起作用。你是否也嘗試使用@using MyNamespace在模板本身中添加命名空間; – marto 2011-05-16 13:23:54