Reputation: 44605
I am working with MVC4 and want to set come custom locations for the view engine to look for views in. At present it will only look in the Shared folder outside of the folder it expects the view to exist in.
I want to add 2 more folder locations for it to look for a view in. How can this be achieved in mvc4? I don't want to manipulate how it works at present, just add extra folders for it to look in.
Note: I already work with display modes with views rendered based on the requesting device - I don't want to affect this with my changes.
Upvotes: 2
Views: 1664
Reputation:
use this code
public class CustomViewEngine : WebFormViewEngine
{
public CustomViewEngine()
{
var viewLocations = new[] {
"~/Views/{1}/{0}.aspx",
"~/Views/{1}/{0}.ascx",
"~/Views/Shared/{0}.aspx",
"~/Views/Shared/{0}.ascx",
"~/AnotherPath/Views/{0}.ascx"
// etc
};
this.PartialViewLocationFormats = viewLocations;
this.ViewLocationFormats = viewLocations;
}
}
Upvotes: 2