26 Using the built-in tag helpers
This chapter covers
- Using a tag helper to create anchor elements that target actions and Razor Pages
- Using tag helpers to manage JavaScript and CSS files
- Using a tag helper to manage image elements
- Using a tag helper to cache fragments of content
- Using a tag helper to generate content based on the hosting environment
ASP.NET Core provides a set of built-in tag helpers that apply the most commonly required element transformations. In this chapter, I explain those tag helpers that deal with anchor, script, link, and image elements, as well as features for caching content and selecting content based on the environment. In chapter 27, I describe the tag helpers that support HTML forms. Table 26.1 puts the built-in tag helpers in context.
Table 26.1 Putting the built-in tag helpers in context
| Question |
Answer |
| What are they? |
The built-in tag helpers perform commonly required transformations on HTML elements. |
| Why are they useful? |
Using the built-in tag helpers means you don’t have to create custom helpers using the techniques in chapter 25. |
| How are they used? |
The tag helpers are applied using attributes on standard HTML elements or through custom HTML elements. |
| Are there any pitfalls or limitations? |
No, these tag helpers are well-tested and easy to use. Unless you have unusual needs, using these tag helpers is preferable to custom implementation. |
| Are there any alternatives? |
These tag helpers are optional, and their use is not required. |