0

I'm currently using NVelocity to render some email templates.

I'm curious how I can do this with the standard ASP.NET MVC view engine i.e. render a view as a string.

Basically I want to pass get the string result of a model binded view and pass this to iTextSharp to generate a PDF.

Thanks. Ben

Ben Foster
  • 34,340
  • 40
  • 176
  • 285

2 Answers2

1

You have a PDF generator that takes html as an arg to generate a pretty PDF?

Look at this blog entry for how to capture a rendered view as a string.

Chad Ruppert
  • 3,650
  • 1
  • 19
  • 19
  • Hi Chad - thanks for the link. This answered my question. That PDF utility (Winnovative Html to PDF Converter) is really neat, just shame about the price. I did manage to get a good solution together using NVelocity and iTextSharp (see http://blogs.planetcloud.co.uk/mygreatdiscovery/post/NVelocity-and-iTextSharp-for-PDF-generation.aspx). For basic order receipts etc. its pretty good. – Ben Foster Mar 18 '10 at 19:46
0

You can use a ContentResult to return Content(yourString, "text/plain"); but you just build the string in the ContentResult method and use no View.

mark123
  • 1,065
  • 1
  • 11
  • 16
  • 1
    @Mark - thanks for the suggestion. However, the reason for wanting to use the View engine was so that I bind the response to a model (e.g. passing in an order object to generate a receipt) = you can't do this with ContentResult. – Ben Foster Mar 18 '10 at 19:41