Following this guide I've been creating an Admin area: https://docs.asp.net/en/latest/mvc/controllers/areas.html
I can navigate to the admin pages by directly typing in the url, however I can't get links to generate
I've tried placing the following on the Admin index.cshtml:
<p><a asp-action="Index">Admin Index</a></p>
<p><a asp-controller="Home" asp-action="Index">Admin Index</a></p>
<p><a asp-area="Admin" asp-controller="Home" asp-action="Index">Admin Index</a></p>
Yet the all end up being non clickable anchors (no href)
In fact, when I view source, I actually still see the "asp-action" etc tags
<a asp-action="Index">Admin Index</a>
MVC doesn't seem to be processing the link helper tags?
Any idea what I've missed? Perhaps a configuration step somewhere?
Thanks
How to create "Area" in ASP.net Core. As we are aware, there is no option to create area by right clicking on project folder. So if we want to create area in Asp.net Core MVC application, Create new folder and name it to area. Within this folder we can create another new folder and give it to any logical name.
ASP.net MVC applications may have one or more areas. So, using Areas, we can divide our large application into smaller functional groups. The logical components such as Model, View and Controller are kept in different folders and MVC framework uses naming conventions to create relations between these components.
An area is effectively a structure inside an app. In an ASP.NET Core web project, logical components like Pages, Model, Controller, and View are kept in different folders. The ASP.NET Core runtime uses naming conventions to create the relationship between these components.
Class namespaces have no effect on MVC's routing. The first two controllers are members of areas, and only match when their respective area name is provided by the area route value. The third controller isn't a member of any area, and can only match when no value for area is provided by routing.
Got it!
I needed to add a _ViewImports.cshtml to my Areas folder
_ViewImports.cshtml needs the following inside:
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
Odd how it wasn't mentioned in the tutorial
Seeing as how this is the first result in searching for my issue and even though my issue was slightly different, I'll post my answer here.
My tags weren't working either. I had this:
<a href="@Url.Action("Queues", "Digium", new {Area = "Reporting"})">
and this:
<a asp-action="CurrentCalls" asp-controller="Digium" asp-area="Reporting">
And nothing was working... it wasn't recognizing the area and the links were coming out as
/Controller/Action?Area=MyArea
I was really confused because I had an area that was working just fine. That's when I realized that I had forgotten to put the Area annotation on the controller:
[Area("Marketing")]
public class LinkedInController : Controller
Don't forget your area annotation!
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