How to load PartialView via Javascript

0

I have an Asp.Net MVC project where there is a method that returns a PartialView :

[HttpPost]
public ActionResult MinhaAction(int param1, int param2)
{
   // ...
   // Código
   // ...

   MigraDoc.DocumentObjectModel.Document doc = new MigraDoc.DocumentObjectModel.Document();
   DocumentRenderer renderer = new DocumentRenderer(doc);
   PdfDocumentRenderer pdfRenderer = new PdfDocumentRenderer();
   pdfRenderer.PdfDocument = outPdf;
   pdfRenderer.DocumentRenderer = renderer;

   MemoryStream ms = new MemoryStream();

   pdfRenderer.Save(ms, false);
   byte[] buffer = new byte[ms.Length];
   ms.Seek(0, SeekOrigin.Begin);
   ms.Flush();
   ms.Read(buffer, 0, (int)ms.Length);

   PdfFormatOptions pfo = ExportOptions.CreatePdfFormatOptions();
   pfo.CreateBookmarksFromGroupTree = true; //habilita tree

   return PartialView("PrintPdf", ms);
}


My PartialView PrintPdf looks like this:

@using myProject.Enumerator
@model Stream

@{

    var file = Model.ToArray();
    Response.Clear();
    Response.ClearContent();
    Response.AddHeader("Content-Length", file.Length.ToString());
    Response.AddHeader("Content-Disopsition", "filename=" + ViewBag.FileName);
    Response.ContentType = "application/pdf";
    Response.BinaryWrite(file.ToArray());
}


As you can see, I'm wanting to return a PDF to the View where I have the following Ajax:

<div id="conteudo-pdf" style="display:none;width:790px;height:590px;"></div>

// ...

 $.ajax({
     beforeSend: function () {
          LoadStart();
     },
     complete: function () {
          LoadStop();
     },
     contentType: 'application/json, charset=utf-8',
     dataType: 'json',
     type: 'POST',
     url: '@Url.Action("MinhaAction", "MeuController")',
     data: JSON.stringify(
         {
             param1: 1,
             param2: 2
         }),
     success: function (data) {
             $("#conteudo-pdf").empty();
             ShowDialog("Title", "#conteudo-pdf", "1024", "660");
             $("#conteudo-pdf").html(data);
         },
    timeout: 420000,
    fail: function (jqXHR, textStatus) {
             if (textStatus === 'timeout') {
                   alert('Failed from timeout');
             }
             alert("Error 007")
     }
});

// ...

function ShowDialog(title, idDiv, largura, altura) {
    $(idDiv).dialog({
        title: title,
        resizable: false,
        width: largura,
        height: altura,
        modal: true,
        position: 'center',
        buttons: [{
            text: Resources.Fechar,
            click: function () {
                $(idDiv).attr("title", "");
                $(this).dialog("close");
            }
        }]
    }).css("font-size", "10px").fadeIn("slow");

    ValidaForm();
}


Unfortunately it has not worked, because the variable data always comes null . I've already tried to send pdf as base64 , but because it has many graphic details, it ends up crashing the browser. I need something light and simple, but keep my Action as POST .

    
asked by anonymous 21.03.2016 / 20:53

0 answers