【发布时间】:2014-02-22 08:53:39
【问题描述】:
我正在做 ajax POST 为:
$.ajax({
type: 'POST',
url: rootUrl("Home/PrintInvoice/12"),
success: function (result) {
$("#TestInvoicePrint").empty();
$("#TestInvoicePrint").html(result);
window.open(result);
}
});
我从 MVC 操作的结果中获取 PDF 文件的位置,
public ActionResult PrintInvoice(long ID)
{
var data = db.Documents.Where(x => x.InvoiceNumber == ID);
ReportDocument rd = new ReportDocument();
rd.Load(Server.MapPath("~/Reports/InvoiceDocument.rpt"));
ConnectionInfo ConnInfo = new ConnectionInfo { ServerName = "10.0.0.154,1433\\sqlexpress", UserID = "CueReader", Password = "CueReader@123", DatabaseName = "Cue" };
ParameterFieldDefinitions parmFields = rd.DataDefinition.ParameterFields;
ParameterValues pvals = new ParameterValues();
rd.ParameterFields["DocumentID"].CurrentValues.IsNoValue = true;
Stream stream = rd.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat);
stream.Seek(0, SeekOrigin.Begin);
return new FileStreamResult(stream, "application/pdf");
}
如何将 PDF 文件从 ajax POST 用于我的 DOM 元素?
【问题讨论】:
-
您可以将其作为 HTTP 获取。
window.open(rootUrl("Home/PrintInvoice/12"))。如果需要,使用 OutputCacheAttribute 来防止缓存。 -
似乎类似于这个问题:stackoverflow.com/questions/9840230/…
-
你能澄清一下你想如何在你的 dom 中使用 PDF 吗? AFAIK,如果你想显示 PDF,你需要嵌入一个阅读器控件。您可能会发现此线程很有用:stackoverflow.com/questions/291813/…
-
而是返回 filestreamresult 将其保存在文件夹中的某个位置,然后返回 filename.pdf 。然后使用它 var iframe = $('
标签: javascript jquery ajax asp.net-mvc