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.

4 Answers 4

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...

Sign up to request clarification or add additional context in comments.

1 Comment

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.
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?

3 Comments

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

Comments

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");

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.