A set of useful, and possibly opinionated, Tag Helpers for ASP.NET Core.
Supported on ASP.NET Core 6.0, & 7.0. Also supported on ASP.NET Core 2.1 when run on .NET Framework 4.7.1 or higher.
This site running on ASP.NET Core 7.0.20 on .NET 7.0.20 on Linux
Installation & Issues
See installation instructions and file issues at GitHub.
Examples
Field Template, Data Annotation, & Model Tag Helpers
Use <any-element asp-display-for="..."> or <display for="..."> to render a model
value using the relevant field display template.
Use <any-element asp-editor-for="..."> or <editor for="..."> to render a model
value using the relevant field editor template.
Use <any-element asp-display-name-for="..."> or <display-name for="..."> to render a model
property's display name using the relevant field display template.
Use <any-element asp-description-for="..."> to display the content of a description from the
DisplayAttribute instance decorating a
Model property. Works on any empty HTML element.
Use <label asp-for="..."> to include the model property's description in the title
attribute.
When using <display for="..." /> or <editor for="..." />:
Use the template-name attribute to override the template used to render the model.
Use the html-field-name attribute to override the HTML field name used to render the model.
Use view-data-* and view-data attributes to provide additional ViewData to the template.
When using <any-element asp-display-for="..."> or
<any-element asp-editor-for="...">:
Use the asp-template-name attribute to override the template used to render the model.
Use the asp-html-field-name attribute to override the HTML field name used to render the model.
Use asp-view-data-* and asp-view-data attributes to provide additional ViewData to the template.
Use <datalist asp-list="..."> to render a <datalist> element containing <option> elements
representing each of the values from the specified list. Set input elements to use the list using the list attribute,
e.g. <input asp-for="..." list="countries" /><datalist id="countries" asp-list="...">
Use <button asp-enabled="..."> to disable/enable button.
Example
Source
Description For Tag Helper
Use <any-element asp-description-for="..."> to display the content of a Description
from the
DisplayAttribute instance decorating a
Model property.
Works on any empty HTML element.
Example
The Customer description is: The Customer Name
Source
Razor Syntax
C# Model
Markdown Tag Helper
Use <markdown> to render markdown in the page/view.
Example
Greetings Elizabeth, from markdown!
This is a list
Of things you could do
With this Tag Helper
Source
By default, indentation is normalized, which is why the previous example renders correctly. To turn off
indentation normalization, set preserve-indentation to true. If you do so, you'll need
to remove leading whitespace between the <markdown> tag and the content.
Source
If you don't, you might end up with unexpected code blocks.
Example
Greetings *Elizabeth*, from **markdown**!
- This is a list
- Of things you could do
- With this Tag Helper
Source
Script Inlining Tag Helper
Use <script src="..." asp-inline="true"> to inline the contents of the referenced JavaScript file in the
element body.
Example
Source
AuthZ Tag Helper
Use <any-element asp-authz="true|false" asp-authz-policy="..."> to specify authoriziation requirements that
must be satisified for this element to be rendered.