So I've been tinkering with View locations for an MVC app I'm working on, specifically because I need to be able to use views/routes for a parent site in a child site.
Ultimately I want to be able to serve up views from a different location, say ~/SiteAViews/.. Where ~ is the root of site B, and the views deposited in site ~/SiteAViews/ are views copied in a post build event from SiteA.
Sounds easy with a custom view engine. However, I've done this in a custom view engine (example change below) adding to the locations for the view and master pages. The problem occurs when accessing a URI, and therefore route that is defined in the SiteA dll (referenced in siteB).
this.ViewLocationFormats = new string[8]
{
"~/Views/{1}/{0}.aspx",
"~/Views/{1}/{0}.ascx",
"~/Views/Shared/{0}.aspx",
"~/Views/Shared/{0}.ascx",
"~/SiteAViews/{1}/{0}.aspx",
"~/SiteAViews/{1}/{0}.ascx",
"~/SiteAViews/Shared/{0}.aspx",
"~/SiteAViews/Shared/{0}.ascx"
};
If I change the view engine, and post build task, to refer to/copy content to ~/views/SiteA/.. rather than ~/SiteAViews/.. it all works great and parses the ViewModel. However, with ~/SiteAViews/.. I receive the following.
Exception type: HttpParseException Exception message: Could not load type 'System.Web.Mvc.ViewPage<'Shared.MyViewModel'>'. at System.Web.UI.TemplateParser.ParseString(String text, VirtualPath virtualPath, Encoding fileEncoding) at System.Web.UI.TemplateParser.ParseFile(String physicalPath, VirtualPath virtualPath) at System.Web.UI.TemplateParser.Parse() at System.Web.Compilation.BaseTemplateBuildProvider.get_CodeCompilerType() at System.Web.Compilation.BuildProvider.GetCompilerTypeFromBuildProvider(BuildProvider buildProvider) at System.Web.Compilation.BuildProvidersCompiler.ProcessBuildProviders() at System.Web.Compilation.BuildProvidersCompiler.PerformBuild() at System.Web.Compilation.BuildManager.CompileWebFile(VirtualPath virtualPath)