Technical Developer Glossary
Find answers for the most frequently asked questions
They enable developers to enrich standard HTML elements with custom attributes that are processed on the server, making the code more readable, maintainable and intuitive.
In short, Tag Helpers are the HTML-friendly way to create views and define UI in ASP.NET Core applications.
Let's explore the ASP.NET Core tag helper features:
Tag Helpers in ASP.NET Core work by allowing developers to create server-side logic that enhances standard HTML elements.
A Tag Helper is implemented as a class that derives from the TagHelper base class. This class contains properties that map to HTML attributes and methods like Process or ProcessAsync that define how the HTML element is modified.
These Tag Helpers are registered in the _ViewImports.cshtml file using the @addTagHelper directive, making them available across Razor views.
When a Razor view is rendered, the Razor engine identifies custom tags associated with Tag Helpers, instantiates the corresponding Tag Helper classes and executes their processing methods to generate the final HTML output with the desired modifications.
Some benefits of the ASP.NET Core tag helper include:
In ASP.NET Core, common Tag Helpers include the Anchor Tag Helper for generating hyperlinks with dynamic attributes, the Cache Tag Helper for caching content and the Environment Tag Helper for conditionally rendering content based on the hosting environment.
The Form Tag Helper simplifies form creation with attributes for model binding, while the Input, Label, Select and TextArea Tag Helpers generate form controls with binding and validation features.
Additionally, the Validation Message and Validation Summary Tag Helpers display validation messages for individual fields or the entire model, respectively. These Tag Helpers enhance development by providing a more intuitive and streamlined way to work with HTML elements in Razor views.
In summary, Tag Helpers in ASP.NET Core provide a way to enhance HTML elements with server-side logic, making Razor views more powerful and easier to maintain. They offer a clean and intuitive syntax that integrates seamlessly with existing HTML and Razor code. Take a look at this ASP.NET Core Tag helpers tutorial for more getting started information.