Atul Warade

Atul Warade

  • NA
  • 1k
  • 447.8k

How to create tag helper in ASP.NET Core 3.0?

Jul 10 2020 2:58 AM
It is a new feature that has been introduced in ASP.NET Core MVC and are C# classes that transform HTML elements in a view. Common uses for tag helpers include URLs for forms using the application’s routing configuration, ensuring that elements of a specific type are styled consistently, and replacing custom shorthand elements with commonly used fragments of content.
 
It enable server-side code to participate in creating and rendering HTML elements in Razor files. Tag helpers are a new feature and similar to HTML helpers, which help us render HTML. Tag helpers can be used to apply certain CSS classes to HTML. For example you could create a tag helper that transforms an element from <button type=”submit” bs-button-color=”danger”>Add</button> to <button type=”submit” class=”btn btn-danger”>Add</button>. The tag helper will recognize the bs-button-color attribute and use its value to set the class attribute on the element sent to the browser. This example might not look very useful, but it provides a foundation for explaining how tag helpers work.
 
For Use Tage Helper :
 
@addTagHelper *,Microsoft.AspNetCore.Mvc.TagHelpers

Answers (3)