在没有 HttpContext 或 ControllerContext 的情况下将 ASP.NET MVC 字符串渲染到视图?
我需要将 ASP.NET MVC 视图呈现为字符串,以便能够通过电子邮件发送它(它是在 .ascx 文件中定义的订单确认电子邮件)。
但是现在我需要能够通过 WCF 服务(将通过 silverlight 访问)来完成此操作,因此我没有 ControllerContext
。此 WCF 服务与我的 MVC 项目包含在同一项目中,因此可以访问我的所有模型等。
我已经在 Stackoverflow 上查看了有关此问题的几个问题,但它们似乎都需要控制器上下文。我以为 mvccontrib 中有东西,但它 似乎不存在不再。
我发现的最接近的是上述问题的接受答案,但不幸的是它与您正在渲染的视图中的 RenderPartial 中断。
我希望与 RenderAction 相关的 ASP.NET MVC 2 的一些幕后工作可能有助于现在实现这一点?
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 question, 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Web 表单视图引擎集成到 MVC 中的方式需要控制器上下文,因为它实际上将模板化/渲染向上冒泡到 ASP.NET Page 类,后者将模板内容直接写入响应流。
我建议您查看 Spark 视图引擎(它将在不进行更改的情况下呈现 WFVE 模板)并使用它从 WCF 服务中生成模板化电子邮件。 Spark 下载中有这方面的示例。
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.
那么为什么不创建一个 ControllerContext,即使 假的?
Why not create a ControllerContext then, even if fake?