Antaris / RazorEngine

Open source templating engine based on Microsoft's Razor parsing engine
http://antaris.github.io/RazorEngine
Other
2.13k stars 578 forks source link

RazorEngine Render ViewComponent And TagHelpers #582

Open shahabksh opened 2 years ago

shahabksh commented 2 years ago

My ultimate goal is to generate output for razor tags

I have a TagHelper With name Ad-Plus.cs

using Microsoft.AspNetCore.Razor.Runtime.TagHelpers; using Microsoft.AspNetCore.Razor.TagHelpers; using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks;

namespace DevCore.TagHelpres { // You may need to install the Microsoft.AspNetCore.Razor.Runtime package into your project [HtmlTargetElement("Ad-Plus")] public class Ad_Plus : TagHelper { public override void Process(TagHelperContext context, TagHelperOutput output) { output.TagName = "div"; output.Attributes.SetAttribute("class", "hr-theme-slash"); output.Attributes.SetAttribute("data-toggle", "modal"); output.Attributes.SetAttribute("data-target", "#plusmodels");

        output.Content.AppendHtml("    <div class='hr-line'></div>");
        output.Content.AppendHtml("         <span class='dx-icon dx-icon-plus'></span>");
        output.Content.AppendHtml("    <div class='hr-line'></div>");

    }
}

}

Now I want to have a Render html TagHelper in output

@using RazorEngine; @using RazorEngine.Templating;

@{ string template = ""; var service = RazorEngineService.Create(); service.AddTemplate("template", template); service.Compile("template"); var result = service.Run("template");
} @result But the output result :