简体   繁体   English

ASP.Net Core Anchor路由到控制器中的操作

[英]ASP.Net Core Anchor route to action in controller

I am trying to make an anchor execute a controller method, which is not working for me. 我正在尝试使锚执行控制器方法,这对我不起作用。 This is my anchor: 这是我的主播:

<div class="topNavigationBar">
    <a href="default/GoToGames">Games</a>
</div>

My controller is called Default and its ActionResult method which I want to execute is called GoToGames : 我的控制器称为Default ,我要执行的ActionResult方法称为GoToGames

public IActionResult GoToGames()
{
    return View("/Views/Games.cshtml");
}

I tried this: 我尝试了这个:

<a asp-controller="Default" asp-action="GoToGames">Apps</a>

Which just makes the anchor unclickable. 这只会使锚点不可点击。 How can I make the anchor route to the ActionResult? 如何将锚定路线传递到ActionResult?

在“视图”文件夹中,创建文件_ViewImports.cshtml并添加以下行:

@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM