【发布时间】:2013-06-14 09:31:26
【问题描述】:
我刚开始使用 RazorEngine,但在使用静态辅助方法时遇到了问题。它只是为模板生成一个 MvcHtmlString/IHtmlString。当调用 Razor.Parse(...) 我得到
RazorEngine.Templating.TemplateCompilationException : Unable to compile template.
Der Typ 'System.Web.IHtmlString' ist in einer nicht referenzierten Assembly definiert. (not referenced)
Fügen Sie einen Verweis auf die Assembly 'System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' hinzu.
我添加了对System.Web、System.Web.Mvc、System.Web.WebPages 的引用。还尝试将它们添加到 cshtml (@using System.Web, @using System.Web.Mvc)。
但是@using System.Web.Mvc 导致.Mvc 在System.Web 中不可用?!
我目前正在尝试在 NUnit 测试中构建模板。
【问题讨论】:
-
好的,如果我在代码中创建
MvcHtmlString,然后再尝试Parse模板,它就可以工作。因此,在 Razor 模板中使用之前,可能必须先在 C# 代码中使用System.Web.Mvc命名空间中的某些内容? -
我也遇到了同样的问题,你找到解决办法了吗?谢谢
-
有人在这里回答我:stackoverflow.com/a/23496144/1875786
标签: c# nunit razorengine