How to debug Razor Asp.Net anchor tag generation when using Controller and Action

53 views Asked by At

I am trying to learn Razor and Asp.Net, following a couple of courses. I see that this snippet of code should work, but the generated link is empty:

<a class="nav-link text-dark" asp-area="" asp-controller="Course" asp-action="Index">Courses</a>

There is a CourseController with an Index action. In fact, Rider is even able to jump to their definition when I click on the attribute values. Nevertheless, the generated anchor tag does not include a link, just the CSS style.

I tried to change the type of link to asp-page, trying to link into the index.cshtml file I have inside a Course folder. But it did not work.

1

There are 1 answers

0
Alberto On

It seems there is no default route. Adding this code to Program.cs seems to fix the issue:

app.MapControllerRoute(
    name: "default",
    pattern: "{controller=Home}/{action=Index}/{id?}");