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

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

    This one keeps the original RazorViewEngine and cleans away the VB extensions.

    //Remove the legacy ASPX view engine
    ViewEngines.Engines.Remove(ViewEngines.Engines.OfType<WebFormViewEngine>().Single());
    
    //Remove VB from the remaining view engine
    var target = ViewEngines.Engines.OfType<RazorViewEngine>().Single();
    (new Expression<Func<RazorViewEngine,string[]>>[] {
        y => y.FileExtensions,
        y => y.ViewLocationFormats,
        y => y.PartialViewLocationFormats,
        y => y.MasterLocationFormats,
        y => y.AreaMasterLocationFormats,
        y => y.AreaPartialViewLocationFormats,
        y => y.AreaViewLocationFormats
    }
    ).Select(y => (PropertyInfo)((MemberExpression)y.Body).Member).ToList()
        .ForEach(y => y.SetValue(target,((string[])y.GetValue(target))
        .Where(x => x.EndsWith("cshtml")).ToArray(),null));
    
    0 讨论(0)
提交回复
热议问题