Creating a Bootstrap button Tag Helper

Tag Helpers are a new addition to ASP.NET MVC Core and can be used to generate HTML markup. The syntax of Tag Helpers is similar to traditional HTML elements, but is still processed on the server.

Although traditional HTML Helpers are still available, Tag Helpers are intended as an alternative, if not replacement, syntax.

To create your own custom Tag Helper that will generate a Bootstrap button, complete the following steps:

  1. Add a new folder called TagHelpers to your project.
  2. Create a new class called BootstrapButtonTagHelper in the TagHelpers folder.
  3. Change the BootstrapButtonTagHelper to inherit from the TagHelper class, which is a built-in class of the Microsoft.AspNetCore.Razor.TagHelpers package.
  4. In order ...

Get Bootstrap for ASP.NET MVC - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.