Which add the addtaghelper expression the views file
Introduction to HTML Tag Helper
• Tag helpers are a new feature that has been introduced in ASP.NET Core MVC and are C# classes that transform HTML elements in a view.
responses sent to clients and that can be used by tag helpers.
1
3
Preparing an Example project
5
6
• As with many MVC features, the best way to understand tag
helpers is to create one, which reveals how they operate and how they fit into an application. In the sections that follow, I go through the process of creating and applying a tag helper that will apply the Bootstrap CSS classes for a button element so that an element like this:
• Tag helpers are derived from the TagHelper class, which is defined in the Microsoft.AspNetCore.Razor.TagHelpers namespace. To create a tag helper, I added a file called ButtonTagHelper.cs file to the
Infrastructure/TagHelpers folder and used it to define the class shown in Listing 23-10.
9
WHAT HAPPENED TO HTML HELPERS?
• Earlier versions of ASP.NET MVC used HTML helpers to generate form elements. HTML helpers were methods accessed through Razor expressions that begin with @Html so that creating an input element for the Population property would be done like this:
Producing Output
• The Process method transforms an element by configuring the TagHelperOutput object that is received as an argument. The TagHelperOuput starts out describing the HTML element as it appears in the Razor view and is modified through the properties and methods described in Table 23-4.
13
Using a Tag Helper
14 |
---|
15