Adding Prefixes to Tag Helpers in MVC 6


Some people have said that they would prefer all Tag Helper elements in MVC 6 to be prefixed. I honestly don't see myself doing this but it is easy to turn on if you prefer tag helper elements to be prefixed with some special text.

Simply add the @tagHelperPrefix directive to the _ViewImports.cshtml file in your project:

@tagHelperPrefix "th:"

Now, Razor will only recognize elements as Tag Helpers if the elements are prefixed with "th:".


You can choose whatever prefix you want for your project. As I said, I probably won't be using this myself but at least there is an easy way to turn on tag helper prefixes for those who want to be very explicit about tag helpers.

One nice thing with prefixes is that it enables is a quick way to identify what tag helpers exist in a project. When you type in the prefix, IntelliSense will show you a list of elements that can be processed by tag helpers:


What do you think? Prefix or not prefix?

Dave Paquette

Email Email
Web Web
Twitter Twitter
GitHub GitHub

Looking for someone else?

You can find the rest of the Western Devs Crew here.

© 2015 Western Devs. All Rights Reserved. Design by Karen Chudobiak, Graphic Designer