TagHelpers are not supported
See original GitHub issueHi,
I would like to use your library for email-templates, which contains links to the application itself. Sadly, RazorLight seems to parse razor code, but not the ASP.NET Core TagHelpers. For example, the asp-controller and asp-action attribute to generate an action-controller link like this:
<a asp-controller="Account" asp-action="Login">Test</a>
Using dependency injection, a instance of IRazorLightEngineis injected in my constructor. There I call the Parsemethod like this:
var html = razorEngineLight.Parse("Shared/Test.cshtml", new object());
But in the rendered html, I don’t get a parsed link like
<a href="/Account/Login">Test</a>
as expected. Instead, I get 1:1 the source code with asp-controller and action attribute like showed above. So it seems that the _ViewImports.cshtml file in the View-folder is not globally parsed like ASP.NET Core do it. I tried to add the tag helpers manually using
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
in the Razor-View, but its not working. As a workaround, I tried to use the old UrlHelpers from ASP.NET like this way:
@{
var link = Url.Action("Login", "Account", null);
}
<a href="@link">Testlink</a>
This is valid code, as it works in a normal Razor-View. But using RazorLight, I got a RazorLight.TemplateCompilationException: Failed to compile generated razor view. See CompilationErrors for detailed information. In the details, Visual Studio show me that there is one CompilationError (Cound = 1) but there seems no way to extend or otherwise view them.
As a result, it seems not possible to create action-controller links using Razor, which is a problem in my point of view. Would be pleased if this could be fixed.
Issue Analytics
- State:
- Created 7 years ago
- Comments:32 (10 by maintainers)

Top Related StackOverflow Question
Still missing for years. I realize this is a free and open source project, but if anyone can give guidance on how to add html helpers to this project so that views work as they do in a vs project I’d be happy to do the work.
Hi there
As mentioned here #16 - taghelpers and UrlHelpers are not implemented. I am going to roll up a stable version soon, and more likely it will not be implemented there, as we are on Release Candidate now. I will add this to backlog, but expect this on the next major release.
In your case you can write pure HTML for building links for now, it’s not critical, but yes, a lot of people were asking where are tag and url helpers, so it has to be added.
Thanks, stay tuned