Как отобразить PDF как поп в Mvc? - PullRequest
0 голосов
/ 13 февраля 2019

Я пытаюсь получить pdf-байтовые данные из базы данных и показывать их как всплывающее окно

Частичное представление

<iframe id="PdfDisplay" style="width:100%;height:80vh" onload=""></iframe>

действие контроллера

public ActionResult PDFDisplay(int id)
    {
        byte[] pdfByte = db.MasterCopyAPIs.Where(w => w.Id == id).Select(w => w.mastercopy).FirstOrDefault();
        //System.IO.File.WriteAllBytes(Server.MapPath(@"~/Files/" + TempData["fileName"].ToString()),pdfByte);
        return File(pdfByte, "application/pdf");
    }

вызов ajax

 function DisplayMaster(id) {
    $.ajax({
        url: '@Url.Action("PDFDisplay", "ProductAPI")/?id=' + id,
        type: 'POST',
        cache: false,
        success: function (data, status, txt) {
            alert(data);
            $("#PdfDisplay").val(data);
            setTimeout(function () {
                window.location.replace('@Url.Action("Index", "ProductAPI")');//Need To Specify which window to redirect
                return true;
            });
        }
    });
}

мой вид вызова

 <a href="" onclick="DisplayMaster(@Model.Id)">@Model.Mastercopyname</a>

1 Ответ

0 голосов
/ 14 февраля 2019
         public ActionResult PDF(string Report)
        localReport.DataSources.Add(reportDataSource);
        localReport.DataSources.Add(reportDataSource2);
        string reportType = Report;
        string mimeType;
        string encoding;
        string fileNameExtension;
        if (reportType == "PDF")
        {
            fileNameExtension = "pdf";
        }
        else if (reportType == "EXCEL")
        {
            fileNameExtension = "xlsx";
        }
        else if (reportType == "WORD")
        {
            fileNameExtension = "docx";
        }
        Warning[] warnings;
        string[] streams;
        byte[] renderedBytes;
        renderedBytes = localReport.Render(reportType, "", out mimeType, out encoding, out fileNameExtension, out streams, out warnings);
        return File(renderedBytes, mimeType);
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...