1
votes

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...

1
Try <a href="@Url.Action("Index", "Home")"></a>J. Doe
Do you perhaps have duplicate calls to .UseMvc() in your Startup.cs? That was the problem here: github.com/aspnet/Mvc/issues/4658Gabriel Luci
@GabrielLuci nope just once.gsharp
@J.Doe same resultgsharp
Does the new project have route attributes on the Home controller too?Gabriel Luci

1 Answers

0
votes

Found the Issue.

I'm using the Smidge as a bundler and Minifier.

I registred the Smidge Middleware before the Mvc Middleware. That seems to mess up the routing. I opened an Issue on githup. See https://github.com/Shazwazza/Smidge/issues/71

Changing the order fixes the problem.