The question has already been asked (and answered):
Render view as string
This is the bit I'm using:
protected string RenderViewToString<T>(string viewPath, T model, System.Web.Mvc.ControllerContext controllerContext) { using (var writer = new StringWriter()) { var view = new WebFormView(viewPath); var vdd = new ViewDataDictionary<T>(model); var viewCxt = new ViewContext(controllerContext, view, vdd, new TempDataDictionary(), writer); viewCxt.View.Render(viewCxt, writer); return writer.ToString(); } }
The best place for this method is the class library project, to which your mvc project has a link. Mostly because you can easily use it in all your applications. But also because this is not the application logic (therefore, it does not belong to the controller) and does not belong to the model. Some things are just utilities.
Please note that for this to work, the viewPath parameter must be the PHYSICAL path to the file, complete with the .aspx extension. You cannot use a route because the WebFormView class requires a physical path in its constructor.
This will allow you to fully view and take into account the main page.
HEALTH WARNING FOR HTML E-MAIL:
HTML letters and the devices where you read them are even more complex and restrictive for design than for websites and browsers. What works in one will not work in the other. Thus, with html letters, you really need to keep it simple! Your beautiful page with menus and relative images, and everything else, JUST DOES NOT WORK on all email devices. As an example, the src attribute of images should be absolute and contain a domain:
This will not work:
<img src="/Images/MyImage.gif" ... />
Bit it will be:
<img src="http://www.mywebsite.com/Images/MyImage.gif" ... />
With these caveats, it works fine, and I use it. Just do not try to send them the full trick of your site, because it will not work!
More importantly:
All CSS should be INLINE and just for the basic style: colors, borders, indents. But there is no swimming and positioning. CSS layouts will not work consistently on all devices!