In my personal project, i got a needs building various layout for each flow .I researched on google and got a solution.
That is customize ViewEngine in MVC. 🙂
Default ViewLocation is:
~/Views/<controller>/<viewname>.aspx
~/Views/<controller>/<viewname>.ascx
For customize default view engine , created a class inherit WebFormViewEngine. For example i created MyViewEngine
public class MyViewEngine : WebFormViewEngine { public MyViewEngine() { base.MasterLocationFormats = new string[] { "~/Themes/{2}/Views/{1}/{0}.master", "~/Themes/{2}/Views/Shared/{0}.master" }; base.ViewLocationFormats = new string[] { "~/Themes/{2}/Views/{1}/{0}.aspx", "~/Themes/{2}/Views/{1}/{0}.ascx", "~/Themes/{2}/Views/Shared/{0}.aspx", "~/Themes/{2}/Views/Shared/{0}.ascx" }; base.PartialViewLocationFormats = ViewLocationFormats ; } public override ViewEngineResult FindView(ControllerContext controllerContext, string viewName, string masterName, bool useCache) { //Customize any path for return ViewEngineResult } }
Add customized viewengine to ViewEngines:
protected void Application_Start() { RegisterRoutes(RouteTable.Routes); // Replace the Default WebFormViewEngine with our custom WebFormThemeViewEngine System.Web.Mvc.ViewEngines.Engines.Clear(); System.Web.Mvc.ViewEngines.Engines.Add(new MyViewEngine()); }
I will post the sample code soon.