Render View (or Partial) In another project?

MartinF picture MartinF · Apr 26, 2009 · Viewed 8.4k times · Source

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.

Answer

tvanfosson picture tvanfosson · Apr 26, 2009

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.