but I decided to download it instead
Yes, it's a good solution.
And about this question:
The problem with this is that the PDF shows hieroglyphics, the whole screen broken, instead of the report
You can return a Base64 encoded string like:
[HttpPost("ExportRotativa")]
public string ExportRotativa()
{
DbImpendingMedicareReportViewModel model = await _IfunctionsUtil.ImpendingMedicareElibigibilityReport();
model.uIElementModel = SessionManagerUtil.GetUIElement(HttpContext.Session);
var pdfResult = new ViewAsPdf("NewPdf", model);
var pdfBytes = await pdfResult.BuildFile(ControllerContext);
string base64EncodedPDF = System.Convert.ToBase64String(pdfByteArray);
return base64EncodedPDF;
}
And
$("#hack").on("click", function () {
win = window.open("", "_blank");
win.document.write(
"<iframe width='100%' height='100%' src='data:application/pdf;base64,
" + encodeURI(htmlData) + "'></iframe> "
)
});
Refer to the apply in this link: https://learn.microsoft.com/en-us/answers/questions/976115/how-to-get-a-pdf-file-and-open-in-new-tab-in-asp-n