Reader small image

You're reading from  Bootstrap for ASP.NET MVC - Second Edition

Product typeBook
Published inSep 2016
Reading LevelIntermediate
Publisher
ISBN-139781785889479
Edition2nd Edition
Languages
Right arrow
Author (1)
Pieter van der Westhuizen
Pieter van der Westhuizen
author image
Pieter van der Westhuizen

Pieter van der Westhuizen is a freelance software and web developer specializing in ASP.NET MVC, web technologies, and MS Office development. He started his career in web development using classic ASP, Visual InterDev, HoTMetaL, and FrontPage. Pieter has over 16 years of experience in the IT industry and is also one of the people fortunate enough to have his hobby become his full-time profession. He is also a technology evangelist for Add-in Express (www.add-in-express.com), which focuses on tools for Microsoft Office integration. This is Pieter's second book and he has been blogging since 2007 on his personal blog at www.mythicalmanmoth.com and on the Add-in Express blog since 2010. He lives with his wife and two dogs in Pretoria, South Africa.
Read more about Pieter van der Westhuizen

Right arrow

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", "attribute"); 
                if (Dismissable) 
                    output.PostContent.SetHtmlContent( 
                $"<button type="button" class="close" data-dismiss="alert">
                <span aria-hidden="true...
lock icon
The rest of the page is locked
Previous PageNext Page
You have been reading a chapter from
Bootstrap for ASP.NET MVC - Second Edition
Published in: Sep 2016Publisher: ISBN-13: 9781785889479

Author (1)

author image
Pieter van der Westhuizen

Pieter van der Westhuizen is a freelance software and web developer specializing in ASP.NET MVC, web technologies, and MS Office development. He started his career in web development using classic ASP, Visual InterDev, HoTMetaL, and FrontPage. Pieter has over 16 years of experience in the IT industry and is also one of the people fortunate enough to have his hobby become his full-time profession. He is also a technology evangelist for Add-in Express (www.add-in-express.com), which focuses on tools for Microsoft Office integration. This is Pieter's second book and he has been blogging since 2007 on his personal blog at www.mythicalmanmoth.com and on the Add-in Express blog since 2010. He lives with his wife and two dogs in Pretoria, South Africa.
Read more about Pieter van der Westhuizen