views:

456

answers:

4

Hello,

i have a solution with the following two projects - MyNamespace.Services and MyNamespace.Web.

Web contains a MVC web application.

In the Service project i have a EmailService class that takes care of sending out emails to the user.

I want to use either a partial or a view (ascx or aspx) for email templates. I have found several solutions on how to render a partial view and get the result as a string which works fine if the template is inside the web project (as it is a controller in the web project that calls the email service).

(the 2 methods i am trying to use is either http://developersisland.blogspot.com/2009/01/renderpartial-to-string-in-aspnet-mvc.html (at the bottom of the blog) or http://www.brightmix.com/blog/how-to-renderpartial-to-string-in-asp-net-mvc/)

But my email templates are located in the Services project.

How can i refference the path to the templates (partial/view) in my Service project from inside the Web project, that works with either LoadControl or RenderPartial which both takes a virtual path as a parameter ?

It seems like no matter what i do the root directory is set to the Web projects directory.

Is it possible ?

Would be nice to be able to make it work independently of the web project somehow.

A: 

I don't think this is possible without developing your own view engine. The default view engine will only look in certain locations for the partial view -- which includes the current view folder and the shared views folder. I don't think you can search for views outside the current project since those views aren't registered with the view engine.

tvanfosson
+1  A: 

You could try creating a custom view engine locator or virtual path provider. Here are a few examples that may help you get going:

Steven Lyons
A: 

All of the links above are good, this might help as well. you will certainly be able to get it to find and use the views. The problem I had was in working with them, there was no code completion etc in the other projects. It was semi possible to get that as well by fiddling around with the project file but to be honest I ended up going with the Grouping solution above

Plug in architecture for ASP.NET MVC

Simon Farrow
+1  A: 

You can consider just creating your HTML helpers to render emails and return it as a string.

Doesn't really matter whether it is partial view or a method returning a string with HTML. i actually think that for your case helper methods would be a better choice.

A simple helper method is also more flexible in the ways you can use it.

User