5

In ASP.NET MVC application I have an action Page() which renders a page (like a wiki page).

Now, I have another action RenderPdf() which should collect the HTML output of Page() and use HTML2PDF component to create PDF version of that page.

How do I collect the HTML output of one action within another action. Note: not in the view, but in the action code directly.

mladen
  • 111
  • 1
  • 4

4 Answers4

0

You can use the MVC Futures assembly.

There is a method called RenderAction() that gets the HTML output of an action, but from inside a view...

Bruno Reis
  • 37,201
  • 11
  • 119
  • 156
  • Actually Bruno, RenderAction() is an HtmlHelper, which is designed to be used within a view. It won't allow mladen to capture the rendered output. – apiguy Aug 24 '09 at 12:45
0

If the pdf is just a copy of the output cant you use javascript to capture the image and pass back to Render PDF?

Or, pass the pdf version to the view within the same model of the first action. Keep it hidden if/until user needs it?

zsharp
  • 13,656
  • 29
  • 86
  • 152
  • zsharp, that is the workaround I was planning to do, but I am not happy with it. I will have cases where PDF will be like 100 pages long. I do not like passing that large HTML back and forth with Javascript. – mladen Aug 25 '09 at 06:26
  • another way might be to create the pdf in the action code and save to file on server just before rendering view. access pdf with unique id sent to view to match id in filename. – zsharp Aug 25 '09 at 17:03
  • zsharp, the problem is - to create PDF i need HTML first, because I am using HTML2PDF component – mladen Aug 26 '09 at 12:12
0

You could check out this awnser to a similar question :

Send ASP.NET MVC action result inside email

Obviously you would need to replace the SendEmailKThx() call with your HTML2PDF PDF generation.

Community
  • 1
  • 1
Matthew Perron
  • 6,201
  • 2
  • 21
  • 24
0

The method suggested by Jan Willem B works and I tested this on ASP .NET MVC 1.

While calling GetActionOutput, use just the name of the controller. e.g if the invoked controller name is AccountController, address it as Account only.

e.g. if you wanted to call Test Method on AccountController, the syntax would be... GetActionOutput("Account", "Test");

user_v
  • 9,628
  • 4
  • 40
  • 32