How to send html from one view to another view?

1

I have a view (View1.cshtml) with filters, a whole layout and a graphic inside a div that is generated according to the filters.

I created another blank view (View2.cshtml) and would like to pass it to just that div with the generated graphic.

Assuming I have this link in View1:

<a href="View2">Enviar HTML</a>

And supposing my controller looks like this:

    public ActionResult View1()
    {
        negocio = new View1Negocio();

        View1DTO dto = new View1DTO ();

        dto.LstExercicios = negocio.ObterExercicios();

        return View(dto);
    }

    public ActionResult View2()
    {
        negocio = new View1Negocio();

        View1DTO dto = new View1DTO ();

        dto.LstExercicios = negocio.ObterExercicios();

        return new ViewAsPdf("View2", dto);
    }

Is there any way to do this? What would I have to do in that code to send this html?

    
asked by anonymous 21.05.2014 / 16:36

1 answer

1

In fact from what I understand, you want to generate the graph and all the information inside a PDF.

I have never done this, but there is a NuGet package that accesses a website and converts it to PDF:

  

link

The project site is:

  

link

But Pechkin does not work with HTML internally. What it does is act as a crawler that downloads the contents of an address and converts it to PDF.

If this works, change the following code in your View:

public FileResult View2()
{
    // configuração global
    GlobalConfig gc = new GlobalConfig();

    // margens, nome do documento, tamanho do papel...
    gc.SetMargins(new Margins(300, 100, 150, 100))
      .SetDocumentTitle("Test document")
      .SetPaperSize(PaperKind.Letter);
    //... etc

    // conversor
    IPechkin pechkin = new SynchronizedPechkin(gc);

    // callbacks
    pechkin.Begin += OnBegin;
    pechkin.Error += OnError;
    pechkin.Warning += OnWarning;
    pechkin.PhaseChanged += OnPhase;
    pechkin.ProgressChanged += OnProgress;
    pechkin.Finished += OnFinished;

    // configuração do objeto
    ObjectConfig oc = new ObjectConfig();

    // codificação, imagens e URL
    oc.SetCreateExternalLinks(false)
      .SetFallbackEncoding(Encoding.ASCII)
      .SetLoadImages(false)
      .SetPageUri("http://enderecodoseusite.com/ControllerDoPDF/View1");
    //... etc

    // gera o PDF
    byte[] pdfBuf = pechkin.Convert(oc);

    return File(pdfBuf, System.Net.Mime.MediaTypeNames.Application.Octet,
                "SeuArquivo.pdf");
}

I think you will need to generate a graph by setting Action to work, not fill in the screen as I imagine it is being done today.

    
21.05.2014 / 19:02