[英]Open PDF file in new browser window in ASP.NET Core 3
I have created the pdf file in the MVC Controller in ASP.NET Core 3. I am returning the FileStreamResult
from this controller. 我想在新的浏览器 window 中打开 PDF。
下面是 HTML 代码 -
<a asp-controller="Score" asp-action="ViewScore" target="_blank" >View PDF</a>
下面是 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;
}
我正在获取 pdf 文件的下载选项。 取而代之的是,我想在新浏览器 window 中打开 pdf。
如果要在新选项卡中打开 pdf,请不要指定fileDownloadName
。
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;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.