Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Why are my Razor pages nav links not working using the default pipeline and configuration

I have several links in this base razor project. For some reason my links stopped working. Here is an example:

<a class="nav-link text-dark"  asp-controller="Contato" asp-action="Contato">Contato</a>

My project layout is pretty simple:

enter image description here

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

When I run the project and click on the non working link it goes to this url:

https://localhost:44372/?action=Contato&controller=Contato

However, when I navigate to the correct URL it works fine:

https://localhost:44372/Contato

I did not change any routing in the program.cs and use the default pipeline stuff:

builder.Services.AddRazorPages();
app.UseRouting();
app.MapRazorPages();

Any help in this routing issue?

>Solution :

There are no controllers or actions in a Razor Pages app – only pages. Therefore your anchor tag helpers should use the asp-page attribute:

<a class="nav-link text-dark"  asp-page="/Contato">Contato</a>

https://www.learnrazorpages.com/razor-pages/tag-helpers/anchor-tag-helper

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading