I have this folder structure for my new Area
This is how I set it up in my startup:
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
routes.MapRoute(
name: "areas",
template: "{area:exists}/{controller=Home}/{action=Index}/{id?}"
);
});
This is how I created my basecontroller
namespace App.Areas.Applications.Controllers
{
[Area("Applications")]
[Authorize]
public abstract class ApplicationsBaseController : Controller
{
}
}
My ApplicationsController then inherits the BaseController
However, when I set a link like this
<li class="nav-item"><a asp-area="Applications" asp-controller="Applications" asp-action="Index" class="nav-link">Applications</a></li>
This is the link that shows up in my url https://localhost:44338/Applications?area=Applications and I get a page cannot be found.
What did I miss when setting up my Area?
EDIT:
When I add [Route("Applications/[controller]")] after my [Area("Applications")], I get this error
An unhandled exception occurred while processing the request. AmbiguousActionException: Multiple actions matched. The following actions matched route data and had all constraints satisfied:
App.Areas.Applications.Controllers.ApplicationsController.Index (App) App.Areas.Applications.Controllers.ApplicationsController.Create (App) App.Areas.Applications.Controllers.ApplicationsController.NewRole (App)
Put it before the default route... like this
app.UseMvc(routes =>
{
routes.MapRoute(
name: "areas",
template: "{area:exists}/{controller=Home}/{action=Index}/{id?}"
);
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