0

I am implementing an offline html to pdf printing function. I want to get the html that would be returned by a view and save it to a file on the server side.

    public JsonResult MyReportOfflinePrint(MyParameters p)
    {
        ActionResult res = MyReportPrintMethod(p);
        using (StreamWriter sw = new StreamWriter("myreport.html")) {
            sw.Write(res.GetTheHtmlString???) 
        }
         return Json("it worked");

I could use http as a web service and call self, but since this view is already available in the same controller that seems like a waste.

I have seen questions about calling a different controller, and returning a raw string as a view, but I want to capture the html string produced by razor engine.

3
  • 1
    So what did your search for "ASP.NET MVC render view to string" yield? Have you found Render a view as a string? Commented Apr 13, 2016 at 14:01
  • 1
    Thanks for pointing me to this. I was missing the magic word Render. Commented Apr 13, 2016 at 15:58
  • No problem, happy to help. Commented Apr 13, 2016 at 18:22

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.