不能使用MvcHtmlString / IHtmlString与RazorEngine [英] Cannot use MvcHtmlString/IHtmlString with RazorEngine

查看:225
本文介绍了不能使用MvcHtmlString / IHtmlString与RazorEngine的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚开始与RazorEngine玩弄,我使用的是静态辅助方法时磕磕绊绊。它只是产生一个MvcHtmlString / IHtmlString模板。当调用Razor.Parse(......)我得到

I just started playing around with the RazorEngine and I'm stumbling when using a static helper method. It just produces an MvcHtmlString/IHtmlString for the template. When calling Razor.Parse(...) I get

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 )。在 .Mvc
,而 @using System.Web.Mvc 结果是无法在的System.Web ?!

I have added references to System.Web, System.Web.Mvc, System.Web.WebPages. Also tried to add them to the cshtml (@using System.Web, @using System.Web.Mvc). But @using System.Web.Mvc results in .Mvc is not available in System.Web?!

我想目前在建的 NUnit的测试模板。

I'm trying to build the templates in NUnit Tests currently.

推荐答案

该RazorEngine有一个类CompilerServicesUtility。这是负责装载和制作组件时可用您的视图进行编译。它在默认情况下返回所有组件加载到当前的AppDomain。

The RazorEngine has a class CompilerServicesUtility. This is responsible for loading and making assemblies available when your view is compiled. It by default returns all assemblies loaded in the current AppDomain.

其位不直观的人看代码,但要确保你的Razor视图编译,你可以使用MvcHtmlString是加载的System.Web和系统的方式之一.Web.Mvc组件到当前的AppDomain使用AppDomain.Current.Load()之前,执行/编译你的看法。

Its bit unintuitive for someone looking at the code, but one way to make sure that your Razor view compiles and you can use MvcHtmlString is to load the System.Web and System.Web.Mvc assemblies into the current AppDomain using AppDomain.Current.Load("") prior to executing/ compiling your view.

这篇关于不能使用MvcHtmlString / IHtmlString与RazorEngine的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆