liveBook · Manning

@addTagHelper directive

As explained in ASP.NET Core in Action, 3e

The @addTagHelper directive is a Razor directive that registers Tag Helpers for use in Razor files.

The @addTagHelper directive registers custom Tag Helpers for use in Razor views, partial views, and layouts. Place it in _ViewImports.cshtml so the registration applies throughout the relevant Razor files. section 32.1.1

Choose the registration form that matches the scope you need:

  • Register one Tag Helper by specifying its fully qualified type and assembly: @addTagHelper CustomTagHelpers.SystemInfoTagHelper, CustomTagHelpers. section 32.1.1
  • Register every Tag Helper in an assembly with wildcard syntax: @addTagHelper *, CustomTagHelpers. section 32.1.1
  • If IntelliSense is missing or Tag Helpers do not appear with Visual Studio’s Tag Helper styling, check the _ViewImports.cshtml registration. section 32.1.1

Registering custom Tag Helpers

A custom SystemInfoTagHelper can be made available with an explicit registration: @addTagHelper CustomTagHelpers.SystemInfoTagHelper, CustomTagHelpers. A wildcard registration instead enables all Tag Helpers from that assembly. After registration, Razor markup such as <system-info></system-info> can use the helper. section 32.1.1 section 32.1.2

How ASP.NET Core in Action, 3e covers it

How deep it goes
Explains explicit and wildcard assembly registration, but does not develop Tag Helper implementation internals.
Examples
Uses SystemInfoTagHelper and IfTagHelper with explicit and wildcard registration examples.
What it assumes
Assumes a custom Tag Helper and its assembly name; teaches how to register either one helper or an entire assembly.
What you can do after
Configure Razor files to recognize custom Tag Helpers through explicit type or wildcard assembly registration.
How it connects
Connects Tag Helpers with Razor templates, _ViewImports.cshtml, assemblies, views, partial views, and layouts.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of ASP.NET Core in Action, 3e. The section links point to the parts of the book it draws on.