tags:

views:

40

answers:

2

I'm including a feature in my web application that notifies a user via e-mail.

Now that I want to HTML format this e-mail, I'm wondering whether it is viable to re-use the core functionality of ASP.NET MVC and have a partial view rendered to a string, so that I can make a partial view with the content of the e-mail. The code in the Service layer would provide the model necessary for the view.

+1  A: 

You can call the view's RenderView method.

Note that this methods takes a ViewContext object, which you'll need to create yourself from the view, the relevant data, and a ControllerContext. I'm not sure which of the properties in ControllerContext are actually used by the view.

SLaks
+1  A: 

You can render view or partial to string: http://www.brightmix.com/blog/how-to-renderpartial-to-string-in-asp-net-mvc/

You do actually need partial, not view, since you probably don't need master page layout with menus and login buttons inside your email ;-)

Note that in the link above there's another link to a shorter method.

queen3
I would update the answer with this: http://www.brightmix.com/blog/renderpartial-to-string-in-asp-net-mvc/ It's a much cleaner version of the original.
Dan Atkinson
I actually mentioned that there's a shorter method.
queen3