question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

TagHelpers are not supported

See original GitHub issue

Hi,

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:open
  • Created 7 years ago
  • Comments:32 (10 by maintainers)

github_iconTop GitHub Comments

6reactions
jjxtracommented, Mar 1, 2019

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.

6reactions
toddamscommented, Oct 22, 2016

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

Visual Studio .Net Core tag helpers are not working
NET core tag helpers have completely stopped working, no idea why as I've not changed anything. I was in work one day, they...
Read more >
How to fix Microsoft.AspNetCore.Mvc ... - SharePointProblems
The fix ended up being simple – just copypaste a suitable _ViewImports.cshtml under your /Views -folder. The _ViewImports.cshtml file is ...
Read more >
How to fix Microsoft.AspNetCore.Mvc.TagHelpers ... - YouTube
Mvc. TagHelpers not being rendered. 2.2K views · 3 years ago ... Taghelpers in Asp.netcore ... NET Core Application is Not Working in...
Read more >
Tag Helpers in ASP.NET Core
Tag Helpers aren't supported in Razor components. For more information, see ASP.NET Core Razor components. What Tag Helpers provide. An HTML- ...
Read more >
Tag Helper Not Working? | The Long Walk
The first step when a tag helper isn't working is always to check the ... Tag Helpers should be converted to proper HTML...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found