public static void Configure(ViewEngineCollection engines) { var razorEngine = engines.FirstOrDefault(f => f.GetType() == typeof(RazorViewEngine)); if (razorEngine != null) { engines.Remove(razorEngine); } engines.Add(new FeaturesRazorViewEngine()); }
/// <summary> /// Replaces the engine matching 'T' with the specified one /// </summary> /// <typeparam name="T"></typeparam> /// <param name="engines"></param> /// <param name="replacement"></param> public static void ReplaceEngine <T>(this ViewEngineCollection engines, IViewEngine replacement) where T : IViewEngine { var engine = engines.SingleOrDefault(x => x.GetType() == typeof(T)); if (engine != null) { engines.Remove(engine); } engines.Add(replacement); }
public static void AdjustViewEngines(ViewEngineCollection viewEngines) { // Turn off WebFormViewEngine. Use Razor only. var webformViewEngine = viewEngines.OfType <WebFormViewEngine>().FirstOrDefault(); if (webformViewEngine != null) { viewEngines.Remove(webformViewEngine); } // Activate MvcCodeRouting view wrapper viewEngines.EnableCodeRouting(); }
/// <summary>注册需要搜索的目录路径</summary> /// <param name="engines"></param> public static void Register(ViewEngineCollection engines) { // 如果没有注册,则注册 var ve = engines.FirstOrDefault(e => e is RazorViewEngineX) as RazorViewEngineX; if (ve == null) { // 干掉旧引擎,使用新引擎 var ve2 = engines.FirstOrDefault(e => e is RazorViewEngine); engines.Remove(ve2); ve = new RazorViewEngineX(); engines.Insert(0, ve); XTrace.WriteLine("注册视图引擎:{0}", ve.GetType().FullName); } }
/// <summary>The update view engines.</summary> /// <param name="engines">The engines.</param> private static void UpdateViewEngines(ViewEngineCollection engines) { var webFormViewEngine = engines.FirstOrDefault(e => e is WebFormViewEngine); if (webFormViewEngine != null) { engines.Remove(webFormViewEngine); } engines.OfType<RazorViewEngine>().ToList().ForEach(engine => engine.FilterLocationFormats( e => e.AreaMasterLocationFormats, e => e.AreaPartialViewLocationFormats, e => e.AreaViewLocationFormats, e => e.FileExtensions, e => e.MasterLocationFormats, e => e.PartialViewLocationFormats, e => e.ViewLocationFormats)); }