ASP.NET MVC避免在文件下载期间“弹出窗口被阻止”(chrome,opera)

时间:2016-06-01 14:35:16

标签: asp.net asp.net-mvc asp.net-mvc-4

我在后端方面有以下代码。 (为了到达这里客户点击按钮,提交带有id的隐藏表单,打开带有... \ DownloadPDF地址的新空白页并开始下载。)

Chrome和Opera将其识别为弹出窗口并默认阻止它。在Firefox中,这段代码正常运行。如何避免它并让它们视为不是弹出窗口?

    public FileContentResult DownloadPDF(Guid id)
    {
        var model = service.GetById(Guid);
        var pdf = printService.CreatePDF(model);
        var fileName =(model.Name + ".pdf").Replace(" ", "_");
        Response.AppendHeader("Content-Disposition", $"attachment; filename*=UTF-8''{Server.UrlEncode(fileName)}");
        return new FileContentResult(pdf, "application/pdf");
    }

Form that is submitted from front-end:
<form action="/Print/DownloadPDF" target="_blank" method="post" id="print-form">
    <input type="hidden" name="id" id="document-id" data-bind="value: Id"/>
</form>

0 个答案:

没有答案