开发者

Render ASP.NET MVC string to View without HttpContext or ControllerContext?

I need to render an ASP.NET MVC view to a string so as to be able to send it via an email (it is an order confirmation email defined in an .ascx file ).

I've successfully been able to render an ASP.NET MVC View to string using one of the methods in this question.

However now I need to be able to do it via a WCF service (that will be accessed via silverlight) and so I don't have a ControllerContext. This WCF service is contained within the same project as my MVC project so has access to all my models etc.

I've looked at several questions on Stackoverflow about this issue, but they all seem to need a controller context. I thought there was something in mvccontrib but it doesn't seem to be there anymore.

The closest I've found is the accepted answer to the aforementioned que开发者_运维问答stion, but it unfortunately breaks with RenderPartial within the view you're rendering.

I'm hoping maybe some of the behind the scenes work for ASP.NET MVC 2 related to RenderAction may help make this possible now?


The way that the web forms view engine is integrated into MVC requires the controller context as it actually bubbles the templating / rendering up to the ASP.NET Page class which writes the template content directly to the response stream.

I suggest you take a look at the spark view engine (which will render WFVE templates without change) and use that to generate the templated emails from within the WCF service. There are examples of this in the Spark download.


Why not create a ControllerContext then, even if fake?

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜