I've tried to combine conventional and attribute routing together.
However it doesn't work as expected, probably because I've missed to do something.
What I have so far:
Routing:
builder.MapRoute("Default", "{controller=Home}/{action=Index}/{id?}");
Home Controller:
public class HomeController : Controller
{
public IActionResult Index()
{
return View();
}
}
Attribute Mapped Controller:
[Route("Admin")]
public class AdminLockController : Controller
{
[Route("ControlCenter")]
public async Task<IActionResult> Index()
{
return View();
}
}
_Layout.cshtml
<a asp-controller="Home" asp-action="Index">
<img id="app-logo-image" src="/img/corporate_logo.png"/>
</a>
Now when when the view Home\Index.cshtml get rendered the link in _Layout.cshtml will become
<a href="/"></a>
(Correct).
But when the view AdminLock\Index.cshtml get rendere the link is <a href=""></a>
(Wrong).
So I guess I need to do some extra configuration, but no idea what. Any hints?
UPDATE 1: It works perfectly in a new created mvc project. So it has to be something wrong in my project... i will try to find out what the issue is...
<a href="@Url.Action("Index", "Home")"></a>
– J. Doe.UseMvc()
in your Startup.cs? That was the problem here: github.com/aspnet/Mvc/issues/4658 – Gabriel Luci