#SharePointProblems | Koskila.net

Solutions are worthless unless shared! Antti K. Koskela's Personal Professional Blog

How to fix Microsoft.AspNetCore.Mvc.TagHelpers not being rendered!

koskila
Reading Time 4 min
Word Count 660 words
Comments 33 comments
Rating 5 (11 votes)
View

Ha - another one, that ended up being a simple fix, but since nobody actually explains it well, took me an hour to figure out.

This post ended up being another example of my "I'm going to document every single fix that took me more than 10 minutes to figure out, since that'll help me (and others) the next time the same issue arises." blogging strategy. Snappy name, right? 😅

Ah, well, naming things is really, really difficult.

Anyway, I ended up banging my head to the wall for a while. Hopefully after reading this, you won't have to.

In addition to the TagHelpers simply not rendering, this article might help you if the call "addTagHelper" is not working, or you get an error along the lines of "the name TagHelper does not exist" in your ASP.NET Core project.

What are TagHelpers then?

I'm quoting and paraphrasing Microsoft for a while here, as they explain it pretty thoroughly:

Tag Helpers enable server-side code to participate in creating and rendering HTML elements in Razor files. There are many built-in Tag Helpers for common tasks - such as creating forms, links, loading assets and more - and even more available in public GitHub repositories and as NuGet packages.

Tag Helpers are authored in C#, and they target HTML elements based on element name, attribute name, or parent tag. For example, the built-in LabelTagHelper can target the HTML element when the LabelTagHelper attributes are applied.

An example of LabelTagHelper would be this:

This built-in helper would fetch the name / display name for a property called Title on the object of type Movie on a view.

If you're familiar with HTML Helpers, Tag Helpers reduce the explicit transitions between HTML and C# in Razor views. In many cases, HTML Helpers provide an alternative approach to a specific Tag Helper, but it's important to recognize that Tag Helpers don't replace HTML Helpers and there's not a Tag Helper for each HTML Helper.

https://docs.microsoft.com/en-us/aspnet/core/mvc/views/tag-helpers/intro?view=aspnetcore-2.2

In short, they reduce the need for you to code menial, boring stuff, that nobody wants to do. That's good stuff.

How to start using "Microsoft.AspNet.Mvc.TagHelpers"?

The bottom line is this - you need to add this line to your _ViewImports.cshtml file. And you need to make SURE, that the particular _ViewImports file is used for your views!

@using Microsoft.AspNetCore.Identity
@using YourApp
@namespace YourNamespace
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers

So what was wrong in my case?

I had downloaded an example from Microsoft, and built on top of that. The sample was great, but not meant to familiarize the user with how routing works in ASP.NET Core - it was just expected to work. But suddenly, for me it stopped working, when I added another controller with views!

So what exactly didn't work?

Code like below wouldn't route anything anywhere. The anchor elements were not links at all.

<!-- Other stuff here -->
   <a asp-action="Edit" asp-route-id="@item.SiteId">Edit</a> |
   <a asp-action="Details" asp-route-id="@item.SiteId">Details</a> |
   <a asp-action="Delete" asp-route-id="@item.SiteId">Delete</a>
<!-- Other stuff continues -->

Why did this work on some Views, but not on others?

And how to fix that?

The fix ended up being simple - just copypaste a suitable _ViewImports.cshtml under your /Views -folder.

The _ViewImports.cshtml file is required in the folder your Views are in, or its parents. The example I was working with only included _ViewImports -files under /Pages and its subfolders.

Check your spelling, too

Still not working? A reader named Jeff shared another important thing to check: the name of the namespace is case-sensitive. You shouldn't capitalize MVC in "Microsoft.AspNetCore.Mvc.TagHelpers". You likely won't get any errors with that misspelling, though, which makes spotting the mistake far more difficult!


Another couple of things, that are super simple when you know them, but frustrating when you're picking something new up!

Further Reading

Comments

Interactive comments not implemented yet. Showing legacy comments migrated from WordPress.
Jay
2019-10-27 21:15:48)
I have the issue with tag Helpers not being rendered. This is a POC application and I have tried the following Installed the NuGet Package for Tag Helpers Added @addTagHelper to _ViewImports file Copied the _ViewImports to the View's sub folder None of these worked !
Jay
2019-11-03 20:35:31
After a while I figured out the silly issue. The following statement should NOT have a semicolon at the end and I had one! @addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
Talha Rafique
2019-11-29 18:34:38)
great bro ! i love your explanation.
2019-12-10 21:02:23
Talha, Thanks for the comment! Happy to hear it was helpful :)
Roman
2019-12-03 19:40:15)
thank you this worked to me on my project asp net core on MAC, a lot of things has to be written from scratch one of them is build razor pages and that means create the "Pages" folder so into this folder those files were not added and any of the hyperlinks were working, after add _ViewImports.cshtml and _ViewStart.cshtml everything started working!
2019-12-10 21:02:05
Hi Roman, Awesome to hear it helped - I suppose templating isn't quite there on Macs? Does the "dotnet new" command (with whatever switches you need to generate new web projects!) not generate the default folders for you at all?
Ajeet
2020-01-17 12:01:01)
greate thanks
2020-01-17 12:24:53
Happy to be of help! :)
Sudhanshu Shekhar
2020-03-07 21:04:09)
I had a similar issue and i struggled a lot for few hours wondering whats going wrong until i came up to this post and got the resolution. Thanks a lot !!
2020-03-08 22:31:47
My pleasure - happy to hear it was helpful! :)
Ryan
2020-03-18 00:42:38)
I did everything your article said to do. I have Asp .net Core 3.1 vs 2019 I installed v2.2 from nuget of the Microsoft.AspNetCore.Mvc.TagHelpers by Microsoft. I added the @addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers in the /Views/_ViewImports.cshtml file along with the other things you mentioned in your article. In the index.cshtml file I added a link like this... Display When I run this app in the Chrome browser and perform a "View Page Source" to display the html, I see the following link like this... Display It's missing all the asp-controller asp-action and asp-route information. Is there something I'm doing wrong?
Ryan
2020-03-18 00:49:19
It appears that I can't submit the html in the post, basciall when I try to use the asp-controller asp-action and the asp-route-id in my source code inside a razor page the rendered html in the browser omits all three tag helpers in the link. Again it's not displaying the controller, action and ID information has a link.
Ryan
2020-03-18 01:45:01
I figured it out! In the Startup.cs file there was a method called app.UseEndpoints... I commented out that method (Normally created when you create a new project) and everything started to work.
2020-03-24 00:13:23
Hi Ryan, Hmm, not sure how the "Display" links in your comment are supposed to look like... Do you have multiple _ViewImports files and what's the folder structure - where's your index.cshtml located?
Paul Thompson
2020-03-24 00:07:59)
Thanks. Saved me a bunch of time.
2020-03-31 14:06:31
My pleasure!
Jeff
2020-05-22 05:33:16)
Just in case anyone else stumbles into this thread... I wound up here with a similar problem, but with a different solution. The entry to import tag helpers in the _ViewImports file is case sensitive, but does NOT provide Intellisense. I had imported (in the proper place): @addTagHelper *, Microsoft.AspNetCore.MVC.TagHelpers That's just second nature to me, to all-caps an acronym. There were no red squiggles, no Intellisense error or warning, so I thought it was OK. It is not. It MUST be: @addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers Note that the latter says "Mvc" instead of "MVC". That incorrect casing caused the anchors not to work, because the views weren't finding the assembly by the poorly-cased name. HTH someone who sees it.
2020-05-22 22:57:09
Hi Jeff, Thanks for your contribution! That's a very valid point - not making an acronym like that both makes sense and absolutely doesn't. I'll update the article's contents with your tip as well. Cheers!
Mick Duprez
2020-08-04 01:27:40
thanks for this, I did the same but I did AspNetcore. What's worse is that most tags were red and no intellisense until a build, after that they worked but I just couldn't get the 'partial' tag to work. I was stumped for ages and as some were working I figured my imports were ok, a nasty, subtle bug!
Prashant Channe
2020-08-11 12:24:57)
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
Added above line in _ViewImports.cshtml, works very well; just do not forget to not to add semicolon after the above line.
Antti K. Koskela
2020-08-12 23:30:08
Thanks for your comment, Prashant! I had to read it 15 times.. "Do not forget to not to add..." :D But yes, you're exactly right. No semicolons in _ViewImports.cshtml or _Imports.razor files.
Bhavin
2020-10-30 19:15:49)
life saver !!! wasted my hours to bind dropdown in Views folder of Areas
2020-10-31 22:51:25
Thanks for your comment, Bhavin! Glad to be of help :)
Rom
2021-03-29 07:21:20)
Thanks. I could register my custom tag helper through _ViewImports in my asp.net core application. I was adding namespace after my taghelper name in @addTagHelper It worked after adding assembly name after comma.
Antti K. Koskela
2021-04-04 23:27:41
Happy to hear the article pointed you to right direction!
Mia
2021-04-12 00:14:29)
Thank you!! I searched all over for how to resolve this.
Antti K. Koskela
2021-04-18 21:32:42
Happy to be of help, Mia! 😊
CodeJameer
2022-06-03 06:07:28)
Thanks much my brother :)
2022-06-11 21:23:10
My pleasure, mate! Happy to be of help :)
2022-06-28 18:59:58
My pleasure, mate!
Whitewater Magpie Ltd.
© 2025
Static Site Generation timestamp: 2025-08-21T07:25:11Z