I have created the pdf file in the MVC Controller in ASP.NET Core 3. I am returning the FileStreamResult
from this controller. I want to open the PDF in a new browser window.
Below is the HTML Code -
<a asp-controller="Score" asp-action="ViewScore" target="_blank" >View PDF</a>
Below is the controller
public async Task<IActionResult> ViewScore()
{
/*Created the pdf doc*/
MemoryStream stream = new MemoryStream();
stream = doc1.Stream;
string contentType = "application/pdf";
string fileName = "sample.pdf";
var file = File(stream, contentType, fileName);
return file;
}
I am getting the downloading option for the pdf file. Instead of that, I want to open the pdf in the new browser window.
Don't specify fileDownloadName
if you want to open the pdf in a new tab.
public async Task<IActionResult> ViewScore()
{
/*Created the pdf doc*/
MemoryStream stream = new MemoryStream();
stream = doc1.Stream;
string contentType = "application/pdf";
string fileName = "sample.pdf";
var file = File(stream, contentType);
return file;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.