I have the following routes set up
app.UseMvc(routes =>
{
routes.MapRoute(
name: "admin",
template: "{controller=Home}/{action=Index}/{id?}",
defaults: new {Area = "Admin"},
constraints: new {HostConstraint = new MyConstraint()});
routes.MapRoute(
name: "admin-rep",
template: "Rep/{controller=Home}/{action=Index}/{id?}",
defaults: new { Area = "" },
constraints: new { HostConstraint = new MyConstraint() });
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
MyConstraint in this case always return true.
<a asp-action="Action">Action</a>
@Html.ActionLink("Action", "Action")
reorder your routes, write admin-rep
first and then admin
app.UseMvc(routes =>
{
routes.MapRoute(
name: "admin-rep",
template: "Rep/{controller=Home}/{action=Index}/{id?}",
defaults: new { Area = "" },
constraints: new { HostConstraint = new MyConstraint() });
routes.MapRoute(
name: "admin",
template: "{controller=Home}/{action=Index}/{id?}",
defaults: new {Area = "Admin"},
constraints: new {HostConstraint = new MyConstraint()});
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
You used Area
but I think you didn't specify asp-area
attribute in tag helper and it cause to this problem. For more informatin to set asp-area
see link below:
Asp.Net MVC Core 1.0 - anchor tag helper with an empty area
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