[英]asp-action and Html.ActionLink not working in asp.net core mvc
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.在经历了 SO 的几个答案之后,我仍然无法让它发挥作用。
I'm just following an example out of a book: Pro ASP.NET Core 3
by Adam Freeman.我只是在学习书中的一个例子:Adam Freeman 的
Pro ASP.NET Core 3
。
Started with a simple .NET core mvc app with the command line:从带有命令行的简单 .NET core mvc 应用程序开始:
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: Index.cshtml
有一个简单的锚标签:
<a asp-action="RsvpForm">RSVP Now</a>
The full file with the project structure:具有项目结构的完整文件:
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:但看起来我的
_ViewImports.cshtml
已经有了它,如下所示:
@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:我什至尝试了 good ol' action link 方法,但这也不起作用:
@Html.ActionLink("RSVP Now", "RsvpForm", "Home", new object { }, new { @class = "btn btn-primary" })
While running the app, I never see the link:在运行应用程序时,我从未看到链接:
The link is not even present in the rendered HTML:该链接甚至不存在于呈现的 HTML 中:
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). PS:我在
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:如果您想查看整个项目,我也已将其推送到 Github:
https://github.com/affableashish/party-invites https://github.com/affableashish/party-invites
Change the _ViewImports.cshtml
file to contain the following:更改
_ViewImports.cshtml
文件以包含以下内容:
@using YouApplicationName
@using YouApplicationName.Models
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.