【发布时间】:2021-04-11 20:06:37
【问题描述】:
我已经阅读了有关如何将存储在 SQL Server db 中的字节数组作为varbinary 并在 Blazor 网站上显示为 PDF 的所有建议。我在 ASP.Net 中取得了成功,背后有 aspx 页面和代码,但我似乎找不到适合 Blazor 的组合(ShowPDF.razor 和背后的代码ShowPDF.razor.cs)
这是我在后面代码中的变体:
-
aReport.ReportDocument 正在从 DB 中返回 aReport.DocumentSize 的字节数组
FileStreamResult GetPDF() { var pdfStream = new System.IO.MemoryStream(); this.rdb = new ReportData(); aReport = rdb.GetWithReport(1); pdfStream.Write(aReport.ReportDocument, 0, aReport.DocumentSize); pdfStream.Position = 0; return new FileStreamResult(pdfStream, new Microsoft.Net.Http.Headers.MediaTypeHeaderValue("application/pdf")); }
OR 2. 将二进制数组直接转为 base 64 编码:
return Convert.ToBase64String(aReport.ReportDocument);
虽然这两个进程返回数据,但我无法找到如何设置剃须刀页面来显示结果。我试过了:
<object src="@Url.Action("GetPDF")"/>
和其他变种都没有成功。
谢谢!
【问题讨论】: