/// <summary> /// 重写FindView /// </summary> /// <param name="controllerContext"></param> /// <param name="viewName"></param> /// <param name="masterName"></param> /// <param name="useCache"></param> /// <returns></returns> public override ViewEngineResult FindView(ControllerContext controllerContext, string viewName, string masterName, bool useCache) { if (controllerContext == null) { throw new ArgumentNullException("controllerContext"); } if (String.IsNullOrEmpty(viewName)) { throw new ArgumentException("viewName is required.", "viewName"); } string controllerName = controllerContext.RouteData.GetRequiredString("controller"); string presentAreaKey; bool isApplication; GetPresentAreaKeyAndIsApplicationFromThemedAttribute(controllerContext, out presentAreaKey, out isApplication); ThemeAppearance themeAppearance = ThemeService.GetRequestTheme(presentAreaKey, controllerContext.RequestContext); if (themeAppearance == null) { throw new ApplicationException("请求的 ThemeAppearance 未找到."); } string viewPath = null; string masterPath; if (isApplication) { string areaName = GetAreaName(controllerContext.RouteData); viewPath = GetViewPathOfApplication(viewName, controllerName, areaName); masterPath = GetLayoutPathOfTheme(themeAppearance, masterName, areaName); } else { viewPath = GetViewPathOfTheme(themeAppearance, viewName, controllerName); masterPath = GetLayoutPathOfTheme(themeAppearance, masterName, null); } #region CreateView string applicationKey = null; if (isApplication) { applicationKey = GetAreaName(controllerContext.RouteData); } ThemedRazorView themedRazorView = new ThemedRazorView(controllerContext, viewPath, layoutPath: masterPath, isPartialView: false, applicationKey: applicationKey, findLayoutPathOfThemeDelegate: GetLayoutPathOfTheme, themeAppearance: themeAppearance, viewPageActivator: ViewPageActivator); #endregion return(new ViewEngineResult(themedRazorView, this)); }
/// <summary> /// 重写FindView /// </summary> /// <param name="controllerContext"></param> /// <param name="viewName"></param> /// <param name="masterName"></param> /// <param name="useCache"></param> /// <returns></returns> public override ViewEngineResult FindView(ControllerContext controllerContext, string viewName, string masterName, bool useCache) { if (controllerContext == null) throw new ArgumentNullException("controllerContext"); if (String.IsNullOrEmpty(viewName)) throw new ArgumentException("viewName is required.", "viewName"); string controllerName = controllerContext.RouteData.GetRequiredString("controller"); string presentAreaKey; bool isApplication; GetPresentAreaKeyAndIsApplicationFromThemedAttribute(controllerContext, out presentAreaKey, out isApplication); ThemeAppearance themeAppearance = ThemeService.GetRequestTheme(presentAreaKey, controllerContext.RequestContext); if (themeAppearance == null) throw new ApplicationException("请求的 ThemeAppearance 未找到."); string viewPath = null; string masterPath; if (isApplication) { string areaName = GetAreaName(controllerContext.RouteData); viewPath = GetViewPathOfApplication(viewName, controllerName, areaName); masterPath = GetLayoutPathOfTheme(themeAppearance, masterName, areaName); } else { viewPath = GetViewPathOfTheme(themeAppearance, viewName, controllerName); masterPath = GetLayoutPathOfTheme(themeAppearance, masterName, null); } #region CreateView string applicationKey = null; if (isApplication) applicationKey = GetAreaName(controllerContext.RouteData); ThemedRazorView themedRazorView = new ThemedRazorView(controllerContext, viewPath, layoutPath: masterPath, isPartialView: false, applicationKey: applicationKey, findLayoutPathOfThemeDelegate: GetLayoutPathOfTheme, themeAppearance: themeAppearance, viewPageActivator: ViewPageActivator); #endregion return new ViewEngineResult(themedRazorView, this); }