Render ASP.NET MVC for viewing without HttpContext or ControllerContext?

I need to display an ASP.NET MVC view for a string in order to be able to send it by email (this is an order confirmation email defined in the .ascx file).

I was able to successfully convert ASP.NET MVC View to a string using one of the methods in this question.

However, now I need to be able to do this through the WCF service (which will be accessed through silverlight), and therefore I do not have a ControllerContext. This WCF service is contained in the same project as my MVC project, and has access to all my models, etc.

I reviewed a few Stackoverflow questions about this issue, but they all seem to need a controller context. I thought there was something in mvccontrib, but it seems like it is not.

The closest I found is the accepted answer to the above question, but it unfortunately breaks with RenderPartial in the view you are viewing.

I hope some of the header work for ASP.NET MVC 2 related to RenderAction can help make this possible now?

+4
source share
3 answers

BuildStarted, and I put together a standalone Razor template engine that might prove useful ( Github ). You will need to adapt the contents of the .ascx into a simple string template, but it should do its job.

If you have NuGet, you can run Install-Package RazorEngine

+2
source

You can check out the following blog post . Also worth Postal .

+1

HttpContextBase HttpRequestBase, .

0

All Articles