I have a Controller with a method like this:
public ActionResult Index()
{
CustomerInfoViewModel viewModel = CustomerInfoModel.Load();
return View("Report", viewModel);
}
Now I'd like to create another method which does the same than this one but returns de HTML (string) instead of the ActionResult. Is there any way to get the HTML that an ActionResult would render or something like that?
Why do I need this? This is a report that I show in HTML. But the user has the possibility to download the PDF with the report. To do that I'm using ABCPdf. I have to ways to build the PDF file.
- From a HTML string. (That's why I want to do what I'm asking).
- From an URL. In this case the server starts a request to that URL (I can use the URL to the method posted above). The problem is开发者_JS百科 that this request is a new one, so I lose the session information (which is used in the report).
Any ideas?
Thanks!
public ActionResult GetPDF()
{
// Do your report generation here
byte[] Buffer = [Get the rendered pdf file]
return File( Buffer, "application/pdf", Server.HtmlEncode("[Report Name]") );
}
精彩评论