Creating a Bootstrap Alert Tag Helper

To create a Bootstrap Alert Tag Helper, which will be a little bit more advanced than the previous example, follow these steps:

  1. Create a new class called BootstrapAlertTagHelper in the TagHelpers folder.
  2. Change the class to inherit from TagHelper.
  3. Add a Boolean property called Dismissable and a string property called Color to the class:
             public bool Dismissable { get; set; } 
            public string Color { get; set; } 
    
  4. Next, override the ProcessAsync method, as illustrated here:
             public override async Task ProcessAsync(TagHelperContext context,        TagHelperOutput output)        {        output.TagName = "div";        output.Attributes.Add("class","alert alert-" + Color);        output.Attributes.Add("role", ...

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.