I have this simple anchor tag.
<a asp-area="Admin" asp-action="Create" asp-controller="Users" class="btn btn-default">Create</a>
The code structure is as follows.
The markup that is generated is as follows
<a class="btn btn-default" href="/Admin/Users">Create</a>
It is missing the action (create) but the rest of the tags seem to be working fine.
Routing setup is as follows
app.UseMvc(
routes =>
{
routes.MapRoute(name: "default", template: "{controller=Home}/{action=Index}/{id?}");
routes.MapRoute(
name: "areaRoute",
template: "{area:exists}/controller=Admin/{action=Index}/{id?}");
});
The solution of this problem is to copy
~/Views/_ViewImports.cshtml
to~/AreaName/Views/_ViewImports.cshtml
This is because the Tag helper is made available because of
@addTagHelper
that is available in the_ViewImports.cshtml page.
Once you have done this, your Tag helper intellisense works as well as your Tag Helper code works!
Hope this helps. Thanks
Reference: [Resolved] Tag helper syntax is not working for the Areas view in ASP.NET Core - DotNetFunda.com
Order matters... put the area route above that of the default.
routes.MapRoute(
name: "adminDefault",
template: "{area:exists}/{controller=Home}/{action=Index}/{id?}");
//catchall
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With