Tag: razorengine

不能在RazorEngine中使用MvcHtmlString / IHtmlString

我刚刚开始使用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 Tests中构建模板。

如何在ASP.NET MVC应用程序的Razor-engine中使用Html.Displar渲染ModelMetadata对象?

我正在尝试利用razor-engine中的DisplayTemplatesfunction自动渲染我的显示视图。 我扫描我的Model ,为我想要显示的每个属性找到正确的ModelMetadata 。 但我无法正确使用Html.DisplayFor呈现属性。 我试图像这样展示我的财产 // First I find the ModelMetadata for the property // I call this statement in a loop and each iteration I pass a different PropertyName to get the correct model ModelMetadata columnMetadata = elementsMetadata.First(x => x.PropertyName == column.PropertyName); // I attempted to render the columnMetadata object like so Html.DisplayFor(x […]

RazorEngine @Html帮助程序工作,但逃避Html

我正在使用RazorEngine来解析网页上html代码段的模板。 (这是一个遗留系统,切换到Mvc Razor视图是不可能的,所以我们将小部分切换到使用RazorEngine,这是有道理的)。 有很多关于SO和互联网的问题试图让Mvc的Html和Url助手与Razor引擎一起工作。 为了使@Html语法起作用,我修改了一些代码,将Html添加到基本模板中: public HtmlHelper Html { get { if (helper == null) { var writer = this.CurrentWriter; //TemplateBase.CurrentWriter var vcontext = new ViewContext() { Writer = writer, ViewData = this.ViewData}; helper = new HtmlHelper(vcontext, this); } return helper; } } public ViewDataDictionary ViewData { get { if (viewdata == null) { viewdata […]

RazorEngine字符串布局和部分?

我像这样使用razor引擎: public class EmailService : IService { private readonly ITemplateService templateService; public EmailService(ITemplateService templateService) { if (templateService == null) { throw new ArgumentNullException(“templateService”); } this.templateService = templateService; } public string GetEmailTemplate(string templateName) { if (templateName == null) { throw new ArgumentNullException(“templateName”); } Assembly assembly = Assembly.GetAssembly(typeof(EmailTemplate)); Stream stream = assembly.GetManifestResourceStream(typeof(EmailTemplate), “{0}.cshtml”.FormatWith(templateName)); string template = stream.ReadFully(); […]