使用标签助手时获取锚标签 link 在新标签页中打开

Getting anchor tag link to open in new tab when using tag helper

使用 asp.net-core-mvc

中的新标签助手
<a class="custom-social-icon" asp-area="" asp-protocol="https" asp-host="www.youtube.com/mysite" >
    <img src="~/images/youtube.gif" alt="youtube_logo" />
</a>

新标签助手中是否有允许 link 在新标签页中打开的设置?因为您不能使用此方法添加 target="_blank"。

此外,使用标签助手和更改页面时,将鼠标悬停在图标上会在使用标准 href 方式 (www.youtube.com/mysite) 时显示正确的 link,但使用tag helper 它将页面路径添加到 url 的末尾 (www.youtube.com/mysite/Home/Contact)。如果使用标签助手,你如何防止这种情况发生?

您可以清除添加空操作和控制器的路径

<a asp-action=""
   asp-controller=""
   asp-area=""
   asp-protocol="https"
   asp-host="www.youtube.com/mysite"
   target="_blank">

我在 Visual Studio 2017 年收到来自目标属性的警告

Attribute is allowed only when 'href' is present

但是该属性仍然呈现给页面

但这一切似乎有点适得其反,为什么不直接使用普通的旧 html

<a href="https://www.youtube.com/mysite" 
   target="_blank">