1

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>&nbsp;@item.Title
</a>

The controller action returns a 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.

Ehsan Sajjad
  • 61,834
  • 16
  • 105
  • 160
lloyd
  • 1,089
  • 1
  • 17
  • 39

1 Answers1

4

You are explicitly specifying to open a new tab/page by using target="blank".

From 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.

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>&nbsp;@item.Title
</a>
Community
  • 1
  • 1
NightOwl888
  • 55,572
  • 24
  • 139
  • 212