Tag helpers represent the way to create custom html elements in asp.net core's Razor templating engine they replace the old and deprecated [Html Helper facility](http://www.tutorialsteacher.com/mvc/html-helpers).

This document is a cheat sheet that outlines briefly the key-points of using existing tag helpers will not be very helpful if you need to understand tag helpers from scratch

A lot of introductory resources are available online if you are not familiar with the concept. The following articles are a good starting point:

- [Introduction to Tag Helpers](https://docs.microsoft.com/en-us/aspnet/core/mvc/views/tag-helpers/intro)
- [Authoring Tag Helpers](https://docs.microsoft.com/en-us/aspnet/core/mvc/views/tag-helpers/authoring)

## Keypoints

- Tag Helpers substitute markup in cshtml files with standard html markup:   
`<hello-world></hello-world>` turns to `<p>Hello World!</p>`
- Built-in tag helpers are available under the `Microsoft.AspNetCore.Mvc.TagHelpers` assembly
- Substitution can be activated by custom html tag name, custom html attribute and standard html elements name: `<label asp-for="Email"></label>`

## Usage

- Tag helpers need to be included in cshtml files by using the `@addTagHelper` directive: <script src="https://gist.github.com/MissaouiChedy/17e60c8e594067302e892531dcafa3ab.js"></script>
- The default asp.net core project template includes `@addTagHelper` in `View/Shared/_ViewImports.cshtml`: <script src="https://gist.github.com/MissaouiChedy/172b3d99633d9c13798b43f6c9969b41.js"></script>
- There is a variety of useful built-in tag helpers ([cache](http://www.davepaquette.com/archive/2015/06/03/mvc-6-cache-tag-helper.aspx), [img](http://www.davepaquette.com/archive/2015/07/01/mvc-6-image-tag-helper.aspx), ...)
- Once included tag helpers can be used in cshtml files and [IntelliSense support](https://docs.microsoft.com/en-us/aspnet/core/mvc/views/tag-helpers/intro#intellisense-support-for-tag-helpers) is available in visual studio
- Some tag helpers provide custom attributes:  
`<hello-world name="Ali"></hello-world>`
- Some tag helpers can accept a C# expression:  
`<hello-world name="new SomeModel() { Id=2149 }"></hello-world>`
- It is possible to use standard html attributes:  
`<hello-world id="the-hello-world" class="a-hello-world"></hello-world>` turns to `<p id="the-hello-world" class="a-hello-world">Hello World!</p>`
- It is possible to remove (uninclude) tag helpers from a specific view by using the `@removeTagHelper` directive:  
`@removeTagHelper img, TechDominator.TagHelpersAssembly`
- It is possible to disable tag helper activation for specific element by using the `!` operator:  
`<!hello-world></!hello-world>` turns to `<hello-world></hello-world>`
- Some tag helpers can accept content and even nested elements which can be tag helpers as well: <script src="https://gist.github.com/MissaouiChedy/afce2ccbf216052e1ec1a06ac1d50883.js"></script>

