按照本指南,我一直在创建一个管理区域: https://docs.asp.net/en/latest/mvc/controllers/areas.html
我可以直接输入网址导航到管理页面,但我无法获取生成链接
我已尝试将以下内容放在Admin index.cshtml上:
<p><a asp-action="Index">Admin Index</a></p>
<p><a asp-controller="Home" asp-action="Index">Admin Index</a></p>
<p><a asp-area="Admin" asp-controller="Home" asp-action="Index">Admin Index</a></p>
然而,最终都是不可点击的锚(没有href)
事实上,当我查看源代码时,我实际上仍然会看到“asp-action”等标签
<a asp-action="Index">Admin Index</a>
MVC似乎没有处理链接助手标记?
知道我错过了什么吗?也许是某个配置步骤?
由于
答案 0 :(得分:15)
知道了!
我需要将_ViewImports.cshtml添加到我的Regions文件夹
_ViewImports.cshtml需要以下内容:
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
奇怪的是教程中没有提到它
答案 1 :(得分:0)
看到这是搜索我的问题的第一个结果,即使我的问题略有不同,我也会在这里发布答案。
我的标签也不起作用。我有这个:
<a href="@Url.Action("Queues", "Digium", new {Area = "Reporting"})">
这:
<a asp-action="CurrentCalls" asp-controller="Digium" asp-area="Reporting">
什么也没起作用...它没有识别出该区域,链接显示为
/Controller/Action?Area=MyArea
我真的很困惑,因为我的区域工作正常。从那时起,我意识到我忘记了将Area注释放在控制器上:
[Area("Marketing")]
public class LinkedInController : Controller
别忘了您的区域注释!
答案 2 :(得分:0)
_ViewImport.cshtml
添加到新创建的区域。"@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers"
添加到 _ViewImports
。这会触发您的链接。