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

后端 未结 7 921
情深已故
情深已故 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:45

    I figured I'd merge the examples from @tugberk and @Dimps:

    public class CSHtmlRazorViewEngine : RazorViewEngine {
        public CSHtmlRazorViewEngine()
            : base() {
            this.AreaMasterLocationFormats = Filter(base.AreaMasterLocationFormats);
            this.AreaPartialViewLocationFormats = Filter(base.AreaPartialViewLocationFormats);
            this.AreaViewLocationFormats = Filter(base.AreaViewLocationFormats);
            this.FileExtensions = Filter(base.FileExtensions);
            this.MasterLocationFormats = Filter(base.MasterLocationFormats);
            this.PartialViewLocationFormats = Filter(base.PartialViewLocationFormats);
            this.ViewLocationFormats = Filter(base.ViewLocationFormats);
        }
    
        private static string[] Filter(
            string[] source) {
            return source.Where(
                s =>
                    s.Contains("cshtml")).ToArray();
        }
    }
    

提交回复
热议问题