Ajax-вызов для отображения PDF в окне кендо не отображает его правильно - MVC - PullRequest
0 голосов
/ 17 декабря 2018

У меня проблема с отображением PDF-файла в окне кендо.

Данные передаются в представление от контроллера, и они отображаются в окне, за исключением того, что они представлены в формате ascii.

Что мне нужно сделать, чтобы он правильно отображался.

Я использую POST для отправки данных в контроллер.

Контроллер

public ActionResult ReportDataView(Test[] items) {
    PrintingBLL oPrintingBll = new PrintingBLL();
    oPrintingBll.ReportType = "1";
    oPrintingBll.ReportFormat = "PDF";
    string temp = "";
    string temp1 = "";
    foreach(var item in items) {
        if (item.Print4AHD == 'Y') {
            temp = temp + item.HBL + ",";
        } else {
            temp1 = temp1 + item.HBL + ",";
        }
    }
    if (temp.EndsWith(",")) {
        temp = temp.TrimEnd(',');
    }
    if (temp1.EndsWith(",")) {
        temp1 = temp1.TrimEnd(',');
    }
    oPrintingBll.Param1 = temp;
    oPrintingBll.Param2 = temp1;
    Byte[] oReportbytes = oPrintingBll.ProcessReports();
    string strByte = null;
    System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding();
    strByte = enc.GetString(oReportbytes);
    strByte = strByte.ToLower();
    if (!(strByte.Substring(0, 5) == "error")) {
        Response.ContentType = "application/pdf";
        Response.AppendHeader("Content-Disposition", "inline; filename=DocumentPDF.PDF");
        if (oReportbytes.Length > 0) {
            Response.AddHeader("Content-Length", oReportbytes.Length.ToString());
        }
        Response.BinaryWrite(oReportbytes);
        Response.Flush();
        Response.Close();
    }
    return Content("Print"); 
}

Просмотр

 $("#PrintButton").click(function () {
      //grid
      debugger;
      var grid = $('#PrintDocumentGrid').data().kendoGrid;
      var sel = $("input:checkbox[id*='selectShipment']:checked", grid.tbody).closest("tr");
      // Get data item for each
      var items = [];
      var obj = {};
      var item = function (hbl, mbl, carrier, Print4AHD) {
          this.HBL = hbl;
          this.MBL = mbl;
          this.CARRIER = carrier;
          this.Print4AHD = Print4AHD;
      }
      $.each(sel, function (idx, row) {
          var rec = grid.dataItem(row);
          items.push(new item(rec.HBL, rec.MBL, rec.Carrier, rec.Print4AHD));
      });
      $.ajax({
          url: '/ActionPages/ReportDataView',
          type: "POST",
          data: JSON.stringify({
              "items": items
          }),
          dataType: 'text',
          contentType: 'application/json;charset=utf-8',
          success: function (data) {
              $("#PrintWindow").html("");
              $("#PrintWindow").data("kendoWindow").setOptions({
                  width: 1300,
                  height: 900,
                  iframe: true,
              });
              kendo.ui.progress($("#PrintViewWindow"), true);
              $("#PrintWindow").prev().find(".k-window-title").text("Print document information");
              var window = $("#PrintWindow").data("kendoWindow");
              window.content(data);
              window.center();
              window.open();
              //$("#PrintWindow").data("kendoWindow").center().open();
          }[enter image description here][1]
      });
 });
...