Url.Action 下载操作导致新标签页在下载前快速 open/close
Url.Action download action causes new tab to open/close quickly before download
我有一些代码可以在剃刀视图中调用控制器,例如
<a target="_blank" href='@Url.Action("ViewFile", "Form", new { id = item.Id })'>
<i class="fa fa-download" aria-hidden="true"></i> @item.Title
</a>
控制器动作returns一个FileContentResult
一切正常,唯一的问题是下载导致选项卡快速打开然后关闭 (google chrome)。
我需要文件能够在不打开选项卡的情况下下载。
您明确指定使用 target="blank"
打开一个新的 tab/page。
来自MDN:
target
Specifies where to display the linked URL. It is a name of, or keyword for, a browsing context: a tab, window, or <iframe>
.
_blank
: Load the URL into a new browsing context. This is usually a tab, but users can configure browsers to use new windows instead.
删除该属性,它不会打开新的 tab/page。
<a href='@Url.Action("ViewFile", "Form", new { id = item.Id })'>
<i class="fa fa-download" aria-hidden="true"></i> @item.Title
</a>
我有一些代码可以在剃刀视图中调用控制器,例如
<a target="_blank" href='@Url.Action("ViewFile", "Form", new { id = item.Id })'>
<i class="fa fa-download" aria-hidden="true"></i> @item.Title
</a>
控制器动作returns一个FileContentResult
一切正常,唯一的问题是下载导致选项卡快速打开然后关闭 (google chrome)。
我需要文件能够在不打开选项卡的情况下下载。
您明确指定使用 target="blank"
打开一个新的 tab/page。
来自MDN:
target
Specifies where to display the linked URL. It is a name of, or keyword for, a browsing context: a tab, window, or
<iframe>
.
_blank
: Load the URL into a new browsing context. This is usually a tab, but users can configure browsers to use new windows instead.
删除该属性,它不会打开新的 tab/page。
<a href='@Url.Action("ViewFile", "Form", new { id = item.Id })'>
<i class="fa fa-download" aria-hidden="true"></i> @item.Title
</a>