[英]Url.Action download action causes new tab to open/close quickly before download
I have some code that calls a controller in razor view like 我有一些代码在剃刀视图中调用控制器,例如
<a target="_blank" href='@Url.Action("ViewFile", "Form", new { id = item.Id })'>
<i class="fa fa-download" aria-hidden="true"></i> @item.Title
</a>
The controller action returns a FileContentResult
控制器动作返回
FileContentResult
It all works fine, the only issue is the download causes a tab to quickly open and then close (google chrome). 一切正常,唯一的问题是下载导致选项卡快速打开然后关闭(谷歌浏览器)。
I need the file to be able to download without the tab opening. 我需要能够在不打开标签的情况下下载文件。
You are explicitly specifying to open a new tab/page by using target="blank"
. 您通过使用
target="blank"
明确指定打开一个新的选项卡/页面。
target
目标
Specifies where to display the linked URL.
指定显示链接URL的位置。 It is a name of, or keyword for, a browsing context: a tab, window, or
<iframe>
.它是浏览上下文的名称或关键字:选项卡,窗口或
<iframe>
。
_blank
: Load the URL into a new browsing context._blank
:将URL加载到新的浏览上下文中。 This is usually a tab, but users can configure browsers to use new windows instead.通常这是一个选项卡,但用户可以将浏览器配置为使用新窗口。
Remove that attribute, and it won't open a new tab/page. 删除该属性,它将不会打开新的标签/页面。
<a href='@Url.Action("ViewFile", "Form", new { id = item.Id })'>
<i class="fa fa-download" aria-hidden="true"></i> @item.Title
</a>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.