简体   繁体   English

如何在 Razor 页面上创建指向存储在 wwwroot 中的图像的超链接?

[英]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.

相关问题 如何正确地将来自 wwwroot 的图像提供给“页面”子文件夹中的剃刀页面? - How do I properly serve images from the wwwroot to razor pages in a “Page” subfolder? 如何在没有控制器的 Razor 页面中找到 wwwroot 的物理路径? - How can I find the physical path of wwwroot, in a Razor page without a controller? 如何在MVC3剃刀视图中显示存储在变量内的图像 - how do I display an image stored inside a variable in an MVC3 Razor View 如何创建我在ASP.net MVC中以VARBINARY数据类型存储在数据库中的图像的EDIT方法和EDIT Razor View? - How to create EDIT method and EDIT Razor View for Image which i stored in database in VARBINARY datatype in ASP.net MVC? 如何在现有PDF中使用iTextSharp插入到另一页的超链接? - How do I insert a hyperlink to another page with iTextSharp in an existing PDF? 如何根据他的ID将超链接放置到另一个页面? - How do I put an hyperlink to another page according with his ID? 如何在 Blazor 中创建 Razor 页面列表 - How can I create a List of Razor Page in Blazor 如何将图片包含到我的 Razor Page 项目中? - How do I include pictures into my Razor Page project? 如何使用模型发布到 Razor 页面 - .netcore 3.0 - How do I post to Razor Page with model - .netcore 3.0 如何按 Razor 页面中的另一个列表过滤列表? - How do I filter a list by another list in a Razor page?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM