[英]How do I create a hyperlink on a Razor page to an image stored in wwwroot?
How do I create a hyperlink to an image stored in wwwroot on a Razor page?如何在 Razor 页面上创建指向存储在 wwwroot 中的图像的超链接?
Example:例子:
@{
var WFR = "~/images/Certifications/" + (@Model.WFR ?? "../LogoSmall.jpg");
<img src="@WFR" asp-append-version="true" /> // Works great!
<a asp-action="@WFR">see document</a> // Fails miserably
}
The img tag renders the image just fine. img 标签可以很好地呈现图像。 But the anchor tag prepends a controller/action which routes me to my error page.
但是锚标记预先设置了一个控制器/操作,它将我路由到我的错误页面。 This is what the tag helper generates: https://localhost:44394/Employment/~/images/Certifications/12144abb-6af2-424f-b005-4c2039228934_WFR2016.jpg.
这是标签助手生成的内容:https://localhost:44394/Employment/~/images/Certifications/12144abb-6af2-424f-b005-4c2039228934_WFR2016.jpg。 Setting asp-controller="" just brings me to the home controller.
设置 asp-controller="" 只是把我带到家 controller。
What am I missing?我错过了什么?
You don't need any tag helpers for this, just set the tag to link to your image -您不需要任何标签助手,只需将标签设置为链接到您的图像 -
<a href="@WFR" target="_blank">see document</a>
A user in another forum suggest this: Url.Content()另一个论坛的用户建议:Url.Content()
<a href="@Url.Content(@WFR)">see document</a>
... and it works!! ......它的工作原理!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.