Friday, January 23, 2015

Customizing View Engines

      protected void Application_Start()
        {
            ViewEngines.Engines.Clear();//This clears all the Web form view engines.
            
            ViewEngines.Engines.Add(new RazorViewEngine()); //This RazorViewEngine() is present in the System.Web.Mvc namespace
        }
 
 
 
  // Now we create our own custom View Engine  
 
// Add a class to App_Start folder (with any name that suits). Then make the class inherit from RazorViewEngine. 
 
 public class MyCustomViewEngine : RazorViewEngine
    {
        public MyCustomViewEngine()
        {
            AreaViewLocationFormats = new[]
             {
             "~/Areas/{2}/Views/{1}/{0}.cshtml",
             "~/Areas/{2}/Views/Shared/{0}.cshtml"
             };
            AreaMasterLocationFormats = new[]
             {
             "~/Areas/{2}/Views/{1}/{0}.cshtml",
             "~/Areas/{2}/Views/Shared/{0}.cshtml"
             };
            AreaPartialViewLocationFormats = new[]
             {
             "~/Areas/{2}/Views/{1}/{0}.cshtml",
             "~/Areas/{2}/Views/Shared/{0}.cshtml"
             };
            ViewLocationFormats = new[]
             {
             "~/Views/{1}/{0}.cshtml",
             "~/Views/Shared/{0}.cshtml"
             };
            MasterLocationFormats = new[]
             {
             "~/Views/{1}/{0}.cshtml",
             "~/Views/Shared/{0}.cshtml"
             };
            PartialViewLocationFormats = new[]
             {
             "~/Views/{1}/{0}.cshtml",
             "~/Views/Shared/{0}.cshtml"
             };
        }
 
    }

0 comments:

Post a Comment

Twitter Delicious Facebook Digg Stumbleupon Favorites More