views:

610

answers:

4

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.

A: 

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
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.
free-dom
Oh, yes, sorry. I will adapt the answer. Thanks
Bruno Reis
A: 

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
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
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
zsharp, the problem is - to create PDF i need HTML first, because I am using HTML2PDF component
mladen
A: 

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.

matthew.perron
+2  A: 

I did a blog post on this subject. You can find it here: http://jwbs-blog.blogspot.com/2009/08/chaining-aspnet-mvc-actions.html

Jan Willem B