Make ASP.NET MVC 3 Razor View Engine ignore .vbhtml files

后端 未结 7 922
情深已故
情深已故 2020-12-24 09:02

How can I remove the VB Razor Engine or configure the RazorViewEngine to not use and look for .vbhtml files on disk? For new ASP.NET MVC 3 Razor projects, I always remove th

7条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-24 09:46

    This is the code for your custom view engine:

    public class CSRazorViewEngine : RazorViewEngine {
    
        public CSRazorViewEngine() {
    
            base.AreaViewLocationFormats = new string[] { 
                "~/Areas/{2}/Views/{1}/{0}.cshtml",
                "~/Areas/{2}/Views/Shared/{0}.cshtml"
            };
    
            base.AreaMasterLocationFormats = new string[] { 
                "~/Areas/{2}/Views/{1}/{0}.cshtml",
                "~/Areas/{2}/Views/Shared/{0}.cshtml"
            };
    
            base.AreaPartialViewLocationFormats = new string[] { 
                "~/Areas/{2}/Views/{1}/{0}.cshtml",
                "~/Areas/{2}/Views/Shared/{0}.cshtml"
            };
    
            base.ViewLocationFormats = new string[] {
                "~/Views/{1}/{0}.cshtml",
                "~/Views/Shared/{0}.cshtml"
            };
    
            base.PartialViewLocationFormats = new string[] {
                "~/Views/{1}/{0}.cshtml",
                "~/Views/Shared/{0}.cshtml"
            };
    
            base.MasterLocationFormats = new string[] {
                "~/Views/{1}/{0}.cshtml",
                "~/Views/Shared/{0}.cshtml"
            };
    
            base.FileExtensions = new string[] { "cshtml" };
        }
    }
    

    Register this on Application_Start method like this:

    ViewEngines.Engines.Clear();
    ViewEngines.Engines.Add(new CSRazorViewEngine());
    

提交回复
热议问题