Skip to content

Commit 66fadc1

Browse files
Update anchor-tag-helper.md (#37119)
* Update anchor-tag-helper.md Update Anchor Tag Helper doc for .NET 6 (#26037) * Apply suggestion from @wadepickett Co-authored-by: Wade Pickett <wpickett@microsoft.com> * Apply suggestion from @wadepickett Co-authored-by: Wade Pickett <wpickett@microsoft.com> * Apply suggestion from @wadepickett Co-authored-by: Wade Pickett <wpickett@microsoft.com> * Apply suggestion from @wadepickett * Apply suggestion from @wadepickett --------- Co-authored-by: Wade Pickett <wpickett@microsoft.com>
1 parent 860fda6 commit 66fadc1

1 file changed

Lines changed: 20 additions & 11 deletions

File tree

aspnetcore/mvc/views/tag-helpers/built-in/anchor-tag-helper.md

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
---
22
title: Anchor Tag Helper in ASP.NET Core
3+
ai-usage: ai-assisted
34
author: pkellner
45
description: Discover the ASP.NET Core Anchor Tag Helper attributes and the role each attribute plays in extending behavior of the HTML anchor tag.
6+
monikerRange: '>= aspnetcore-6.0'
57
ms.author: wpickett
68
ms.custom: mvc
7-
ms.date: 10/13/2019
9+
ms.date: 05/08/2026
810
uid: mvc/views/tag-helpers/builtin-th/anchor-tag-helper
911
---
12+
1013
# Anchor Tag Helper in ASP.NET Core
1114

1215
By [Peter Kellner](https://peterkellner.net) and [Scott Addie](https://github.com/scottaddie)
@@ -65,9 +68,14 @@ Consider the following controller action:
6568

6669
[!code-csharp[](samples/TagHelpersBuiltIn/Controllers/SpeakerController.cs?name=snippet_SpeakerDetailAction)]
6770

68-
With a default route template defined in *Startup.Configure*:
6971

70-
[!code-csharp[](samples/TagHelpersBuiltIn/Startup.cs?name=snippet_UseMvc&highlight=8-10)]
72+
With a default route template defined in `Program.cs`:
73+
74+
```csharp
75+
app.MapControllerRoute(
76+
name: "default",
77+
pattern: "{controller=Home}/{action=Index}/{id?}");
78+
```
7179

7280
The MVC view uses the model, provided by the action, as follows:
7381

@@ -193,13 +201,9 @@ The generated HTML:
193201
<a href="/Sessions">View Sessions</a>
194202
```
195203

204+
196205
> [!TIP]
197-
> To support areas in a Razor Pages app, do one of the following in `Startup.ConfigureServices`:
198-
>
199-
> * Set the [compatibility version](xref:mvc/compatibility-version) to 2.1 or later.
200-
> * Set the <xref:Microsoft.AspNetCore.Mvc.RazorPages.RazorPagesOptions.AllowAreas%2A?displayProperty=nameWithType> property to `true`:
201-
>
202-
> [!code-csharp[](samples/TagHelpersBuiltIn/Startup.cs?name=snippet_AllowAreas)]
206+
> To support areas in a Razor Pages app, ensure that area routing is enabled in your app's routing configuration. Use the minimal hosting model and configure area routes in *Program.cs* as needed.
203207
204208
#### Usage in MVC
205209

@@ -228,10 +232,15 @@ The generated HTML:
228232
<a href="/Blogs/Home/AboutBlog">About Blog</a>
229233
```
230234

235+
231236
> [!TIP]
232-
> To support areas in an MVC app, the route template must include a reference to the area, if it exists. That template is represented by the second parameter of the `routes.MapRoute` method call in *Startup.Configure*:
237+
> To support areas in an MVC app, the route template must include a reference to the area, if it exists. Configure area routes in *Program.cs* using `MapControllerRoute` with an area pattern, for example:
233238
>
234-
> [!code-csharp[](samples/TagHelpersBuiltIn/Startup.cs?name=snippet_UseMvc&highlight=5)]
239+
> ```csharp
240+
> app.MapControllerRoute(
241+
> name: "mvcAreaRoute",
242+
> pattern: "{area:exists}/{controller=Home}/{action=Index}");
243+
> ```
235244
236245
### asp-protocol
237246

0 commit comments

Comments
 (0)