我们有一个“导出为 pdf”按钮,单击该按钮会生成一份冗长的报告。 PDF 使用 Rotativa 生成.我们需要在生成 PDF 时显示一条消息(简单),并在生成 PDF 后关闭它(困难)。我在 ViewAsPdf() 方法中没有看到任何使我们能够在生成 PDF 后关闭消息的 Hook 。有没有人能够解决这个问题?什么钩子(Hook),如果有的话?
我试图在生成 PDF 后隐藏消息。
非常感谢
View 中的消息
<!-- The message we show to the user after they click the export to PDF button -->
<div id="pdfProcessing" style="display: none; border:1px solid #666666;">
<img src="@Url.Content("~/Content/images/logo.png")" alt="@Index.PdfProcessing ..." />
<h2>@Index.PdfProcessing ...</h2>
<div>@Index.PdfProcessingMessage</div>
</div>
Javascript 按钮点击处理程序
//Displays message when the export to PDF button is clicked
<script type="text/javascript">
$("#export-pdf-btn").click(function () {
$('#pdfProcessing').show();
});
</script>
Controller 操作
// Export to PDF button action handler
public ActionResult Pdf(string districtId, int year, int month)
{
return new ViewAsPdf("Index", EducationReportTasks.BuildViewModel(User, districtId, year, month, true))
{
FileName = districtId + "-" + year + "-" + month + "-report.pdf"
};
}
最佳答案
您应该使用 javascript 下载该文件。也许你可以使用这样的东西:https://github.com/johnculviner/jquery.fileDownload
关于c# - 使用 C# 和 Rotativa 生成 PDF 后删除状态消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26124672/