[英]How to enable a file download via anchor in MVC
I have the following: 我有以下几点:
<a class="download" href='/doc.txt' download>Download txt</a>
And this file is in the root of my web project. 该文件位于我的Web项目的根目录中。 When I click, chrome says Failed - no file
. 当我单击时,chrome表示Failed - no file
。 How do I let folks download a given file via anchor with MVC? 如何让人们通过MVC通过锚点下载给定文件?
I've seen some solutions with complex controller logic / Razor - I'm just looking to provide a direct path to a publicly accessible file. 我已经看到了一些具有复杂控制器逻辑/ Razor的解决方案-我只是想提供直接访问公共文件的路径。
/
refers to the site root, and ~/
refers to the application root. /
表示站点根, ~/
表示应用程序根。
So in your case, you more than likely want this: 因此,就您而言,您极有可能希望这样做:
<a class="download" href='~/doc.txt' download>Download txt</a>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.