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:
Add a new folder called
TagHelpers
to your project.Create a new class called
BootstrapButtonTagHelper
in theTagHelpers
folder.Change the
BootstrapButtonTagHelper
to inherit from theTagHelper
class, which is a built-in class of theMicrosoft.AspNetCore.Razor.TagHelpers
package.In order to use the
TagHelper
class, add the following to the top of theBootstrapButtonTagHelper
class:using Microsoft.AspNetCore.Razor.TagHelpers;
Next, add two properties, called
Color
andStyle
, to the class. The two properties' data types will...