ASP.NET Core provides many built-in Tag Helpers to help you create the necessary HTML elements for many scenarios. However, they do not cover all scenarios. Sometimes, you may want to make some changes to a generated HTML element, or you may want to create an HTML element with new properties, or a new HTML element altogether. You are not restricted to using the existing Tag Helpers in the ASP. NET Core application. You can create your own Tag Helper if the existing Tag Helpers do not suit your needs. Let's create a simple Tag Helper to create an email link:
<a href="mailto:mugil@dotnetodyssey.com">
There are a couple of ways to create Tag Helpers: by implementing the ITagHelper interface or inheriting the TagHelper class. The TagHelper class has a Process method that you can override to write custom Tag Helpers. The TagHelper class also has the TagHelperOutputparameter, which you can use to write and generate the desired output HTML. So, it is preferable to create Tag Helpers by inheriting from the TagHelper class.
Our objective is to write a custom email Tag Helper so that when someone uses that Tag Helper, which is <email mailTo="mugil@greatestretailstore.com"></email>, it is converted to the following line of code:
<a href="mailto:mugil@greatestretailstore.com">Drop us a mail</a>