Creates TIP explaining usage of HtmlAttributeName in custom Tag Helper (#26962)

* Adds note explaining HtmlAttributeName usage

* changes HtmlAttributeName hint to TIP

* Fixes TIP syntax

* removes link to HtmlAttributeName API docs

* Updates

* Update aspnetcore/mvc/views/tag-helpers/authoring.md

* restores f4949b6, moves down and removes TIP markup

Co-authored-by: Luke Latham <1622880+guardrex@users.noreply.github.com>
Co-authored-by: Rick Anderson <3605364+Rick-Anderson@users.noreply.github.com>
pull/26998/head
Alexander Wicht 2022-09-14 20:40:27 +02:00 committed by GitHub
parent 39a6ff8b1c
commit 86bbca8f9e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 15 additions and 0 deletions

View File

@ -117,6 +117,21 @@ That approach works for the attribute "href" as long as it doesn't currently exi
With a self-closing email tag helper, the output would be `<a href="mailto:Rick@contoso.com" />`. Self-closing anchor tags are not valid HTML, so you wouldn't want to create one, but you might want to create a tag helper that's self-closing. Tag helpers set the type of the `TagMode` property after reading a tag. With a self-closing email tag helper, the output would be `<a href="mailto:Rick@contoso.com" />`. Self-closing anchor tags are not valid HTML, so you wouldn't want to create one, but you might want to create a tag helper that's self-closing. Tag helpers set the type of the `TagMode` property after reading a tag.
You can also map a different attribute name to a property using the [`[HtmlAttributeName]` attribute](xref:Microsoft.AspNetCore.Razor.TagHelpers.HtmlAttributeNameAttribute).
To map an attribute named `recipient` to the `MailTo` property:
```csharp
[HtmlAttributeName("recipient")]
public string? MailTo { get; set; }
```
Tag Helper for the `recipient` attribute:
```html
<email recipient="…"/>
```
### ProcessAsync ### ProcessAsync
In this section, we'll write an asynchronous email helper. In this section, we'll write an asynchronous email helper.