asp-controller 和 asp-action 属性不起作用 [英] asp-controller and asp-action attributes not working

查看:29
本文介绍了asp-controller 和 asp-action 属性不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有谁知道我错过了什么,为什么那些 asp-controller 和 asp-action 标签对我不起作用.我正在 ASP.NET MVC Core 中实现一个项目.

Would anyone know what I am missing, why those asp-controller and asp-action tags are not working for me. I am implementing a project in ASP.NET MVC Core.

这不会触发:

<a asp-controller="App" asp-action="Trips" class="btn btn-lg btn-success">Go to Trips</a>

Razor 工作正常:

Razor works fine:

@Html.ActionLink("Go to Trips", "Trips", "App", new object { }, new { @class = "btn btn-lg btn-success" })

我是否需要配置一些服务才能工作.而且,哪种方式是首选?Razor 在 MVC 中非常流行,这些 asp- 标签是一种新的、更好的方法吗?

Do I need to configure some service for that to work. And also, which way is preferred? Razor is pretty popular with MVC, are those asp- tags a new, better way?

推荐答案

经过一点点挖掘我发现asp-controllerasp-action 属性被调用锚标记助手,并且是

After a little bit of digging I found that asp-controller and asp-action attributes are called anchor tag helpers, and are part of the

Microsoft.AspNetCore.Mvc.TagHelpers 命名空间

Microsoft.AspNetCore.Mvc.TagHelpers namespace

显然它是使用 Razor 的替代方法.我能够通过创建_ViewImports.cshtml"并将以下内容添加到文件中来解决该问题:

Apparently it is an alternative to using Razor. I was able to resolve the issue by creating '_ViewImports.cshtml' and adding the below into the file:

@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers

完成后,锚标记助手被识别,按钮开始按预期工作.

Once done that, anchor tag helpers were recognized and button start working as anticipated.

这篇关于asp-controller 和 asp-action 属性不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆