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", "attribute"); if (Dismissable) output.PostContent.SetHtmlContent( $"<button type="button" class="close" data-dismiss="alert"> <span aria-hidden="true...