asp-controller和asp-action属性不起作用 [英] asp-controller and asp-action attributes not working
问题描述
谁会知道我所缺少的,为什么那些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>
剃刀工作正常:
@Html.ActionLink("Go to Trips", "Trips", "App", new object { }, new { @class = "btn btn-lg btn-success" })
我是否需要配置一些服务才能正常工作.而且,哪种方式更可取? Razor在MVC中非常受欢迎,这些asp-tag是一种更好的新方法吗?
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-controller和asp-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屋!