asp-action and Html.ActionLink not working in asp.net core mvc

2.2k views Asked by At

Edit: After couple computer restarts, it started working now. Very weird! Thank you everyone for their time. :)

After going through few answers from SO, I'm still unable to make it work.

I'm just following an example out of a book: Pro ASP.NET Core 3 by Adam Freeman.

Started with a simple .NET core mvc app with the command line:

dotnet new globaljson --sdk-version 3.1.100 --output PartyInvites
dotnet new mvc --no-https --output PartyInvites --framework netcoreapp3.1

The controller setup:

public class HomeController : Controller
{
    public IActionResult Index()
    {
        return View();
    }

    public IActionResult RsvpForm()
    {
        return View();
    }
}

The Index.cshtml has that simple anchor tag:

<a asp-action="RsvpForm">RSVP Now</a>

The full file with the project structure: enter image description here I've seen in many answers that we need to use this:

@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers

but it looks like I already have that in my _ViewImports.cshtml which looks like this:

@using PartyInvites
@using PartyInvites.Models
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers

I even tried the good ol' action link method, but that didn't work either:

@Html.ActionLink("RSVP Now", "RsvpForm", "Home", new object { }, new { @class = "btn btn-primary" })

While running the app, I never see the link: enter image description here

The link is not even present in the rendered HTML: enter image description here

What could I be doing wrong here? Thank you for your time!

PS: I'm on Visual Studio Community 2019 for Mac (macOs Catalina v 10.15.7).

If you'd like to look at the whole project, I've pushed it on Github as well:

https://github.com/affableashish/party-invites

1

There are 1 answers

0
MacDonald Ejime  Oghenefejiro On

Change the _ViewImports.cshtml file to contain the following:

@using YouApplicationName
@using YouApplicationName.Models
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers