【问题标题】:Convert Html to Pdf using Rotativa in AspNetCore在 AspNetCore 中使用 Rotativa 将 Html 转换为 Pdf
【发布时间】:2018-12-19 12:39:31
【问题描述】:

我使用rotativa 在asp net core 2.0 中生成pdf 视图。

生成效果很好,我的疑问是关于响应。如果我使用这个代码块工作,当我点击按钮时它会自动下载:

@using (Html.BeginForm(null, null, FormMethod.Get, new { @action = action , @class="block"}))
{
    <button type="submit">Send</button>
}

但我需要通过ajax 发送请求。它也可以,但是我不知道在返回数据时如何下载文件。例如,按照ajax 请求:

function pdf() {
    $.ajax({
        type: "GET",
        url: url,
        data: {
            'Id': Id,
            'p': p
        },
        beforeSend: function () {
            console.log('Wait...');
        },
        success: function (data) {
            console.log('Success! (I need to download file here)')
        },
        error: function (data) {
            alert('error');
        }
    });
}

这是我用来在服务器中生成的代码:

return new ViewAsPdf(view, obj) { FileName = product + ".pdf" };

【问题讨论】:

    标签: javascript c# ajax asp.net-mvc asp.net-core


    【解决方案1】:

    已经回答here

    您可以动态创建锚元素并以编程方式单击它或使用Download js

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-08-09
      • 1970-01-01
      • 2014-03-03
      • 2021-06-25
      • 2014-03-23
      • 2016-01-09
      • 2013-10-30
      • 1970-01-01
      相关资源
      最近更新 更多