开发者

ASP.NET MVC 3 get HTML from viewmodel

开发者 https://www.devze.com 2023-03-12 00:45 出处:网络
I have a Controller with a method like this: public ActionResult Index() { CustomerInfoViewModel viewModel = CustomerInfoModel.Load();

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.

  1. From a HTML string. (That's why I want to do what I'm asking).
  2. 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]") );
    }
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号