Add folders for mvc4 viewer to search

I am working with MVC4 and want to set custom locations for the view engine to search for views. Currently, it will only look in a shared folder outside of the folder where it expects the view to exist.

I want to add 2 more folder locations to search for. How can this be done in mvc4? I don't want to manipulate how this currently works, just add additional folders to view.

Note. I am already working with display modes with views generated from the requesting device. I don't want to influence this with my changes.

+3


source to share


1 answer


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;
        }
    }

      

+2


source







All Articles