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:
- Create a new class called
BootstrapAlertTagHelper
in theTagHelpers
folder. - Change the class to inherit from
TagHelper
. - Add a Boolean property called
Dismissable
and astring
property calledColor
to the class:public bool Dismissable { get; set; } public string Color { get; set; }
- 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.