Weird behaviour with controller name in ASP.NET Core 6.0 MVC

Viewed 42

I'm not a developer by trade so please go easy. I expect I'm missing something obvious but this is what I'm experiencing.

A new ASP.NET Core 6.0 MVC project just started in VS 2022, in nav items one the menu one of the links isn't being generated correctly.

These are the nav items I'm generating:

<li class="nav-item">
    <a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Index">Home</a>
</li>
<li class="nav-item">
    <a class="nav-link text-dark" asp-area="" asp-controller="Technical" asp-action="Monitoring">Monitoring</a>
</li>
<li class="nav-item">
    <a class="nav-link text-dark" asp-area="" asp-controller="Admin" asp-action="Index">Admin</a>
</li>
<li class="nav-item">
    <a class="nav-link text-dark" asp-area="" asp-controller="Finance" asp-action="Telephony">Finance</a>
</li>
<li class="nav-item">
    <a class="nav-link text-dark" asp-area="" asp-controller="Financ" asp-action="Telephony">Finance</a>
</li>

In my controllers I have a Admin, Finance, Home and Technical controllers.

This is what is being generated:

<li b-fcse4o214h class="nav-item">
    <a class="nav-link text-dark" href="/">Home</a>
</li>
<li b-fcse4o214h class="nav-item">
    <a class="nav-link text-dark" href="/Technical/Monitoring">Monitoring</a>
</li>
<li b-fcse4o214h class="nav-item">
    <a class="nav-link text-dark" href="/Admin">Admin</a>
</li>
<li b-fcse4o214h class="nav-item">
    <a class="nav-link text-dark" href="/Telephony">Finance</a>
</li>
<li b-fcse4o214h class="nav-item">
    <a class="nav-link text-dark" href="/Financ/Telephony">Finance</a>
</li>

The first 3 links work fine, the fifth one doesn't work as I have intentionally mis-spelled the controller name to test this, but the fourth link doesn't have the "Finance" included in the href

Could someone shed some light on what I might have got wrong please?

1 Answers

Sorted it. I used https://code-maze.com/file-upload-aspnetcore-mvc/ for reference for adding a file upload, the controller code on that page had [HttpPost("FileUpload")] removing the ("FileUpload") to leave [HttpPost] resolved it for me.

Given that it allowed me to put any junk in the controller name to test it, I was surprised that it behaved like this.

Anyway, thank you to Okan Karadag for making me look further in to the controller code.

Related