Наследование: System.Web.Mvc.BuildManagerViewEngine
        public IViewEngine CreateModulesViewEngine(CreateModulesViewEngineParams parameters) {
            var areaFormats = new[] {
                                        "~/Core/{2}/Views/{1}/{0}.cshtml",
                                        "~/Modules/{2}/Views/{1}/{0}.cshtml",
                                        "~/Themes/{2}/Views/{1}/{0}.cshtml",
                                    };

            //Logger.Debug("AreaFormats (module): \r\n\t-{0}", string.Join("\r\n\t-", areaFormats));

            var universalFormats = parameters.VirtualPaths
                .SelectMany(x => new[] {
                                           x + "/Views/{0}.cshtml",
                                       })
                .ToArray();

            //Logger.Debug("UniversalFormats (module): \r\n\t-{0}", string.Join("\r\n\t-", universalFormats));

            var viewEngine = new RazorViewEngine {
                MasterLocationFormats = DisabledFormats,
                ViewLocationFormats = universalFormats,
                PartialViewLocationFormats = universalFormats,
                AreaMasterLocationFormats = DisabledFormats,
                AreaViewLocationFormats = areaFormats,
                AreaPartialViewLocationFormats = areaFormats,
            };

            return viewEngine;
        }
Пример #2
0
        public static string RenderViewToString(string controllerName, string viewName, object viewData, List<KeyValuePair<string, object>> additionalData)
        {
            var context = HttpContext.Current;
              var contextBase = new HttpContextWrapper(context);
              var routeData = new RouteData();
              routeData.Values.Add("controller", controllerName);

              var controllerContext = new ControllerContext(contextBase,
            routeData,
            new EmptyController());

              var razorViewEngine = new RazorViewEngine();
              var razorViewResult = razorViewEngine.FindView(controllerContext,
            viewName,
            "",
            false);

              ViewDataDictionary vdd = new ViewDataDictionary(viewData);
              if (additionalData != null && additionalData.Any())
            additionalData.ForEach(vdd.Add);

              var writer = new StringWriter();
              var viewContext = new ViewContext(controllerContext,
            razorViewResult.View,
            vdd,
            new TempDataDictionary(),
            writer);
              razorViewResult.View.Render(viewContext, writer);

              return writer.ToString();
        }
Пример #3
0
        private static RazorViewEngine CreateViewEngine()
        {
            var ret = new RazorViewEngine();

            ret.AreaMasterLocationFormats = 
                ret.AreaViewLocationFormats =
                ret.AreaPartialViewLocationFormats =
                new string[]
            {
                "~/Areas/{2}/Views/{1}/{0}.cshtml",
                "~/Branding/Views/Shared/{0}.cshtml",
                "~/Areas/{2}/Views/Shared/{0}.cshtml",
            };

            ret.MasterLocationFormats = 
                ret.ViewLocationFormats  =
                ret.PartialViewLocationFormats =
                new string[]
            {
                "~/Branding/Views/{1}/{0}.cshtml",
                "~/Views/{1}/{0}.cshtml",
                "~/Branding/Views/Shared/{0}.cshtml",
                "~/Views/Shared/{0}.cshtml",
            };

            return ret;
        }
Пример #4
0
        protected void Application_Start()
        {
            ViewEngines.Engines.Clear();
            var viewEngine = new RazorViewEngine();
            viewEngine.ViewLocationCache = new TwoLevelViewCache(viewEngine.ViewLocationCache);
            ViewEngines.Engines.Add(viewEngine);

            AreaRegistration.RegisterAllAreas();

            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            BundleConfig.RegisterBundles(BundleTable.Bundles);
            RouteConfig.RegisterRoutes(RouteTable.Routes);

            ModelMetadataProviders.Current = new CachedDataAnnotationsModelMetadataProvider();

            MvcHandler.DisableMvcResponseHeader = true;

            ScriptManager.ScriptResourceMapping.AddDefinition("jQuery", new ScriptResourceDefinition
            {
                Path = "~/Js/jquery-2.1.1.js",
                DebugPath = "~/Js/jquery-2.1.1.js",
                CdnPath = "https://code.jquery.com/jquery-2.1.1.min.js",
                CdnDebugPath = "https://code.jquery.com/jquery-2.1.1.min.js",
                CdnSupportsSecureConnection = true,
                LoadSuccessExpression = "window.jQuery"
            });
        }
Пример #5
0
        public static void Start()
        {
            // Clears all previously registered view engines.
            ViewEngines.Engines.Clear();

            // Registers our Razor C# specific view engine.
            // This can also be registered using dependency injection through the new IDependencyResolver interface.
            var viewEngine = new RazorViewEngine();

            viewEngine.AreaPartialViewLocationFormats = new List<string>(
                        viewEngine.AreaPartialViewLocationFormats.Concat(new string[]
                        {
                            "~/Areas/{2}/Views/{1}/_{0}.cshtml",
                            "~/Areas/{2}/Views/{1}/_{0}.vbhtml",
                            "~/Areas/{2}/Views/Shared/_{0}.cshtml",
                            "~/Areas/{2}/Views/Shared/_{0}.vbhtml"
                        })).ToArray();

            viewEngine.PartialViewLocationFormats = new List<string>(
                        viewEngine.PartialViewLocationFormats.Concat(new string[]
                        {
                            "~/Views/{1}/_{0}.cshtml",
                            "~/Views/{1}/_{0}.vbhtml",
                            "~/Views/Shared/_{0}.cshtml",
                            "~/Views/Shared/_{0}.vbhtml"
                        })).ToArray();

            ViewEngines.Engines.Add(viewEngine);
        }
Пример #6
0
        public IViewEngine CreateModulesViewEngine(CreateModulesViewEngineParams parameters) {
            //TBD: It would probably be better to determined the area deterministically from the module of the controller, not by trial and error.
            var areaFormats = parameters.ExtensionLocations.Select(location => location + "/{2}/Views/{1}/{0}.cshtml").ToArray();

            //Logger.Debug("AreaFormats (module): \r\n\t-{0}", string.Join("\r\n\t-", areaFormats));

            var universalFormats = parameters.VirtualPaths
                .SelectMany(x => new[] {
                                           x + "/Views/{0}.cshtml",
                                       })
                .ToArray();

            //Logger.Debug("UniversalFormats (module): \r\n\t-{0}", string.Join("\r\n\t-", universalFormats));

            var viewEngine = new RazorViewEngine {
                MasterLocationFormats = DisabledFormats,
                ViewLocationFormats = universalFormats,
                PartialViewLocationFormats = universalFormats,
                AreaMasterLocationFormats = DisabledFormats,
                AreaViewLocationFormats = areaFormats,
                AreaPartialViewLocationFormats = areaFormats,
            };

            return viewEngine;
        }
        public void CreateController_DummyController_NewControllerViewEnginesHaveAdditinalSearchPaths()
        {
            //Arrange
            var controllerFactory = new FrontendControllerFactory();
            controllerFactory.RegisterController(typeof(DummyController).Name, typeof(DummyController));

            var viewEngine = new RazorViewEngine();
            ViewEngines.Engines.Add(viewEngine);
            try
            {
                //Act
                var controller = (Controller)controllerFactory.CreateController(new DummyHttpContext().Request.RequestContext, "Dummy");

                //Assert
                var controllerVe = controller.ViewEngineCollection.OfType<RazorViewEngine>().FirstOrDefault();
                Assert.IsNotNull(controllerVe, "The newly created controller does not have the expected view engine.");

                var containerVp = "~/" + FrontendManager.VirtualPathBuilder.GetVirtualPath(typeof(DummyController).Assembly);
                Assert.IsTrue(controllerVe.ViewLocationFormats.Any(v => v.StartsWith(containerVp)),
                    "The newly created controller does not have its container path in the view locations.");
            }
            finally
            {
                ViewEngines.Engines.Remove(viewEngine);
            }
        }
        public void CreateController_DecoratedWithViewEnhanceViewEnginesAttribute_NewControllersViewEnginesHaveCustomTransformations()
        {
            //Arrange
            var controllerFactory = new FrontendControllerFactory();
            controllerFactory.RegisterController(typeof(DummyEnhancedController).Name, typeof(DummyEnhancedController));

            var viewEngine = new RazorViewEngine();
            ViewEngines.Engines.Add(viewEngine);
            try
            {
                //Act
                var controller = (Controller)controllerFactory.CreateController(new DummyHttpContext().Request.RequestContext, "DummyEnhanced");

                //Assert
                var controllerVe = controller.ViewEngineCollection.OfType<RazorViewEngine>().FirstOrDefault();
                Assert.IsNotNull(controllerVe, "The newly created controller does not have the expected view engine.");

                Assert.IsTrue(controllerVe.ViewLocationFormats.Any(p => p.StartsWith("~/" + DummyEnhancedController.CustomControllerPath)),
                    "The newly created controller does not have its custom path in the view locations.");
            }
            finally
            {
                ViewEngines.Engines.Remove(viewEngine);
            }
        }
Пример #9
0
		/// <summary>
		/// Create the view engine.
		/// </summary>
		public static void Init() {
			if (!Config.DisableManager) {
				// Create new precompiled view engine
				var engine = new PrecompiledMvcEngine(typeof(ManagerModule).Assembly) {
					UsePhysicalViewsIfNewer = true
				} ;
				engine.PartialViewLocationFormats = engine.PartialViewLocationFormats.Union(ExtensionsFolder).ToArray();
				var standard = new RazorViewEngine() ;
				standard.PartialViewLocationFormats = standard.PartialViewLocationFormats.Union(ExtensionsFolder).ToArray() ;

				ViewEngines.Engines.Insert(0, standard) ;
				ViewEngines.Engines.Insert(1, engine) ;

				VirtualPathFactoryManager.RegisterVirtualPathFactory(engine) ;

				// Register the manager area
				var manager = new ManagerRegistration() ;
				var context = new AreaRegistrationContext(manager.AreaName, RouteTable.Routes) ;
				manager.RegisterArea(context) ;

				// Register custom model binders
				RegisterBinders() ;

				// Register json deserialization for post data
				ValueProviderFactories.Factories.Add(new JsonValueProviderFactory());

				// Register application part
				ApplicationPart.Register(new ApplicationPart(typeof(ManagerModule).Assembly, "~/")) ;
			}
		}
        /// <summary>
        /// 创建模块视图引擎。
        /// </summary>
        /// <param name="parameters">创建模块视图引擎所需的参数。</param>
        /// <returns>视图引擎。</returns>
        public IViewEngine CreateModulesViewEngine(CreateModulesViewEngineParams parameters)
        {
            var areaFormats = new[] {
                                        "~/Core/{2}/Views/{1}/{0}.cshtml",
                                        "~/Modules/{2}/Views/{1}/{0}.cshtml",
                                        "~/Themes/{2}/Views/{1}/{0}.cshtml",
                                    };

            var universalFormats = parameters.VirtualPaths
                .SelectMany(x => new[] {
                                           x + "/Views/{0}.cshtml",
                                       })
                .ToArray();

            var viewEngine = new RazorViewEngine
            {
                MasterLocationFormats = DisabledFormats,
                ViewLocationFormats = universalFormats,
                PartialViewLocationFormats = universalFormats,
                AreaMasterLocationFormats = DisabledFormats,
                AreaViewLocationFormats = areaFormats,
                AreaPartialViewLocationFormats = areaFormats,
            };

            return viewEngine;
        }
Пример #11
0
 private static void OnlyUseRazorViewEngine()
 {
     System.Web.Hosting.HostingEnvironment.RegisterVirtualPathProvider(new CustomVirtualProviderPath());
     var engine = new RazorViewEngine();
     //engine.ViewLocationFormats = new[] { "~/bin/Views/{1}/{0}.cshtml", "~/Views/Shared/{0}.cshtml" };
     //engine.PartialViewLocationFormats = engine.ViewLocationFormats;
     ViewEngines.Engines.Clear();
     ViewEngines.Engines.Add(engine);
 }
 public static string RenderViewToString(ControllerContext ct, string viewName, object viewData)
 {
     var razorViewEngine = new RazorViewEngine();
     var razorViewResult = razorViewEngine.FindView(ct, viewName, "", false);
     var writer = new StringWriter();
     var viewContext = new ViewContext(ct, razorViewResult.View, new ViewDataDictionary(viewData), new TempDataDictionary(), writer);
     razorViewResult.View.Render(viewContext, writer);
     return writer.ToString();
 }
Пример #13
0
 public NustacheView(
     RazorViewEngine engine,
     ControllerContext controllerContext,
     string viewPath,
     string masterPath)
 {
     _engine = engine;
     _controllerContext = controllerContext;
     _viewPath = viewPath;
     _masterPath = masterPath;
 }
Пример #14
0
        private RazorViewEngine CreateRealViewEngine()
        {
            lock (_lock)
            {
                string settingsTheme;
                try
                {
                    settingsTheme = _defaultTheme;
                    if (settingsTheme == _lastTheme)
                    {
                        return _lastEngine;
                    }
                }
                catch (Exception)
                {
                    return _defaultViewEngine;
                }

                _lastEngine = new RazorViewEngine();

                _lastEngine.PartialViewLocationFormats =
                    new[]
                    {
                        "~/Themes/" + settingsTheme + "/Views/{1}/{0}.cshtml",
                        "~/Themes/" + settingsTheme + "/Views/Shared/{0}.cshtml",
                        "~/Themes/" + settingsTheme + "/Views/Shared/{1}/{0}.cshtml",
                        "~/Themes/" + settingsTheme + "/Views/Extensions/{1}/{0}.cshtml",
                        "~/Views/Extensions/{1}/{0}.cshtml"
                    }.Union(_lastEngine.PartialViewLocationFormats).ToArray();

                _lastEngine.ViewLocationFormats =
                    new[]
                    {
                        "~/Themes/" + settingsTheme + "/Views/{1}/{0}.cshtml",
                        "~/Themes/" + settingsTheme + "/Views/Extensions/{1}/{0}.cshtml",
                        "~/Views/Extensions/{1}/{0}.cshtml"
                    }.Union(_lastEngine.ViewLocationFormats).ToArray();

                _lastEngine.MasterLocationFormats =
                    new[]
                    {
                        "~/Themes/" + settingsTheme + "/Views/{1}/{0}.cshtml",
                        "~/Themes/" + settingsTheme + "/Views/Extensions/{1}/{0}.cshtml",
                        "~/Themes/" + settingsTheme + "/Views/Shared/{1}/{0}.cshtml",
                        "~/Themes/" + settingsTheme + "/Views/Shared/{0}.cshtml",
                        "~/Views/Extensions/{1}/{0}.cshtml"
                    }.Union(_lastEngine.MasterLocationFormats).ToArray();

                _lastTheme = settingsTheme;

                return _lastEngine;
            } 
        }
Пример #15
0
        protected void Application_Start()
        {
            //added to improve performance
            ViewEngines.Engines.Clear();
            IViewEngine razorEngine = new RazorViewEngine() { FileExtensions = new string[] { "cshtml" } };
            ViewEngines.Engines.Add(razorEngine);

            AreaRegistration.RegisterAllAreas();
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            //BundleConfig.RegisterBundles(BundleTable.Bundles);
        }
Пример #16
0
 protected void Application_Start()
 {
     ViewEngines.Engines.Clear();
     IViewEngine razorEngine = new RazorViewEngine() { FileExtensions = new string[] { "cshtml" } };
     ViewEngines.Engines.Add(razorEngine);
     //Database.SetInitializer(new MigrateDatabaseToLatestVersion<eQuizContext, Configuration>());
     /////////////////////////////////////////////////////////////////
     AreaRegistration.RegisterAllAreas();
     FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
     RouteConfig.RegisterRoutes(RouteTable.Routes);
     BundleConfig.RegisterBundles(BundleTable.Bundles);
 }
 public ViewModelSpecifiedViewEngine()
     : base(typeof(MvcApplication).Assembly)
 {
     razorViewEngine = new RazorViewEngine();
     #if DEBUG
     UsePhysicalViewsIfNewer = true;
     PreemptPhysicalFiles = false;
     #else
     UsePhysicalViewsIfNewer = false;
     PreemptPhysicalFiles = true;
     #endif
 }
        public void DisableVbhtml(RazorViewEngine engine)
        {
            if (engine == null)
                return;

            engine.AreaViewLocationFormats = RemoveVbhtml(engine.AreaViewLocationFormats);
            engine.AreaMasterLocationFormats = RemoveVbhtml(engine.AreaMasterLocationFormats);
            engine.AreaPartialViewLocationFormats = RemoveVbhtml(engine.AreaPartialViewLocationFormats);
            engine.ViewLocationFormats = RemoveVbhtml(engine.ViewLocationFormats);
            engine.MasterLocationFormats = RemoveVbhtml(engine.MasterLocationFormats);
            engine.PartialViewLocationFormats = RemoveVbhtml(engine.PartialViewLocationFormats);
            engine.FileExtensions = RemoveVbhtml(engine.FileExtensions);
        }
Пример #19
0
        protected string RenderViewToString(string controllerName, string viewName, object viewData)
        {
            using (var writer = new StringWriter())
            {
                var routeData = new RouteData();
                routeData.Values.Add("controller", controllerName);
                var razorViewEngine = new RazorViewEngine();
                var razorViewResult = razorViewEngine.FindView(ControllerContext, viewName, "", false);

                var viewContext = new ViewContext(ControllerContext, razorViewResult.View, new ViewDataDictionary(viewData), new TempDataDictionary(), writer);
                razorViewResult.View.Render(viewContext, writer);
                return writer.ToString();
            }
        }
        public static void RegisterWebEngines()
        {
            ViewEngines.Engines.Clear();
            var razorViewEngine = new RazorViewEngine();

            if (Configuration.Instance.IsDebug())
            {
                ViewEngines.Engines.Add(new ProfilingViewEngine(razorViewEngine));
            }
            else
            {
                ViewEngines.Engines.Add(razorViewEngine);
            }
        }
Пример #21
0
        protected void Application_Start()
        {
            ViewEngines.Engines.Clear(); // Remove view engines
            var engine = new RazorViewEngine();
            //engine.ViewLocationCache = new TwoLevelViewCache(engine.ViewLocationCache);
            ViewEngines.Engines.Add(engine); //Added a new razor view engine

            AreaRegistration.RegisterAllAreas();
            GlobalConfiguration.Configure(WebApiConfig.Register);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);

            ConfigureModeAttribute();
        }
        public static string RenderViewToString(string controllerName, string viewName, object viewData)
        {
            using (var writer = new StringWriter())
            {
                var routeData = new RouteData();
                routeData.Values.Add("controller", controllerName);
                var fakeControllerContext = new ControllerContext(new HttpContextWrapper(new HttpContext(new HttpRequest(null, "http://google.com", null), new HttpResponse(null))), routeData, new FakeController());
                var razorViewEngine = new RazorViewEngine();
                var razorViewResult = razorViewEngine.FindView(fakeControllerContext, viewName, "", false);

                var viewContext = new ViewContext(fakeControllerContext, razorViewResult.View, new ViewDataDictionary(viewData), new TempDataDictionary(), writer);
                razorViewResult.View.Render(viewContext, writer);
                return writer.ToString();
            }
        }
Пример #23
0
 //http://wouterdekort.blogspot.co.uk/2012/10/rendering-aspnet-mvc-view-to-string-in.html
 public static string RenderViewToString(ComplianceReviewReportViewModel viewData)
 {
     var controllerName = "Document";
     var viewName = "ActionPlan";
     var context = HttpContext.Current;
     var contextBase = new HttpContextWrapper(context);
     var routeData = new RouteData();
     routeData.Values.Add("controller", controllerName);
     var controllerContext = new ControllerContext(contextBase, routeData, new DocumentController());
     var razorViewEngine = new RazorViewEngine();
     var razorViewResult = razorViewEngine.FindView(controllerContext, viewName, "", false);
     var writer = new StringWriter();
     var viewContext = new ViewContext(controllerContext, razorViewResult.View, new ViewDataDictionary(viewData), new TempDataDictionary(), writer);
     razorViewResult.View.Render(viewContext, writer);
     return writer.ToString();
 }
Пример #24
0
        private RazorViewEngine CreatePMIViewEngine()
        {
            var pmiViewEngine = new RazorViewEngine();
            var db = new pmiEntities();

            this.theme = db.SiteInfoes.FirstOrDefault().theme;

            pmiViewEngine.PartialViewLocationFormats = new []
                {
                    "~/Themes/" + theme + "/Views/{1}/{0}.cshtml",
                    "~/Themes/" + theme + "/Views/Shared/{0}.cshtml",
                    "~/Themes/" + theme + "/Views/Shared/{1}/{0}.cshtml"
                }.Union(pmiViewEngine.PartialViewLocationFormats).ToArray();

            pmiViewEngine.AreaPartialViewLocationFormats = new[]
                {
                    "~/Themes/" + theme + "/Areas/{2}/Views/{1}/{0}.cshtml",
                    "~/Themes/" + theme + "/Areas/{2}/Views/Shared/{0}.cshtml",
                    "~/Themes/" + theme + "/Areas/{2}/Views/Shared/{1}/{0}.cshtml",
                }.Union(pmiViewEngine.AreaPartialViewLocationFormats).ToArray();

            pmiViewEngine.ViewLocationFormats = new []
                {
                    "~/Themes/" + theme + "/Views/{1}/{0}.cshtml"
                }.Union(pmiViewEngine.ViewLocationFormats).ToArray();

            pmiViewEngine.AreaViewLocationFormats = new[]
                {
                    "~/Themes/" + theme + "/Areas/{2}/Views/{1}/{0}.cshtml"
                }.Union(pmiViewEngine.AreaViewLocationFormats).ToArray();

            pmiViewEngine.MasterLocationFormats = new []
                {
                    "~/Themes/" + theme + "/Views/{1}/{0}.cshtml",
                    "~/Themes/" + theme + "/Views/Shared/{0}.cshtml",
                    "~/Themes/" + theme + "/Views/Shared/{1}/{0}.cshtml"
                }.Union(pmiViewEngine.MasterLocationFormats).ToArray();

            pmiViewEngine.AreaMasterLocationFormats = new[]
                {
                    "~/Themes/" + theme + "/Areas/{2}/Views/{1}/{0}.cshtml",
                    "~/Themes/" + theme + "/Areas/{2}/Views/Shared/{0}.cshtml",
                    "~/Themes/" + theme + "/Areas/{2}/Views/Shared/{1}/{0}.cshtml",
                }.Union(pmiViewEngine.AreaMasterLocationFormats).ToArray();

            return pmiViewEngine;
        }
Пример #25
0
 protected void Application_Start()
 {
     DependencyConfig.SetUpDependencies();
     AreaRegistration.RegisterAllAreas();
     AuthConfig.RegisterAuth();
     FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
     RouteConfig.RegisterRoutes(RouteTable.Routes);
     WorldDominationRouteConfig.RegisterRoutes(RouteTable.Routes);
     BundleConfig.RegisterBundles(BundleTable.Bundles);
     ApiConfig.ConfigureApi(GlobalConfiguration.Configuration);
     //MiniProfilerPackage.PreStart();
     MapperConfig.ConfigureMapper();
     var razorViewEngine = new RazorViewEngine();
     razorViewEngine.ViewLocationCache = new TwoLevelViewCache(razorViewEngine.ViewLocationCache);
     ViewEngines.Engines.Clear();
     ViewEngines.Engines.Add(razorViewEngine);
     ModelBinders.Binders.Add(typeof(User), new UserModelBinder());
 }
        protected void Application_Start()
        {
            ViewEngines.Engines.Clear();
            var razorViewEngine = new RazorViewEngine();
            ViewEngines.Engines.Add(razorViewEngine);



            AreaRegistration.RegisterAllAreas();

            GlobalConfiguration.Configure(WebApiConfig.Register);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);

            log4net.Config.XmlConfigurator.Configure();
           // RouteTable.Routes.MapHubs();
        }
Пример #27
0
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);

            GlobalConfiguration.Configure(WebApiConfig.Register);

            //Razor 엔진만 로딩함
            ViewEngines.Engines.Clear();
            IViewEngine razorEngine = new RazorViewEngine() { FileExtensions = new string[] { "cshtml" } };
            ViewEngines.Engines.Add(razorEngine);
            //ViewEngines.Engines.Add(new RazorViewEngine());

            // Autofac and Automapper configurations
            AutofacModuleConfig.Run();
        }
Пример #28
0
        public IViewEngine CreateThemeViewEngine(CreateThemeViewEngineParams parameters) {
            // Area: if "area" in RouteData. Url hit for module...
            // Area-Layout Paths - no-op because LayoutViewEngine uses multi-pass instead of layout paths
            // Area-View Paths - no-op because LayoutViewEngine relies entirely on Partial view resolution
            // Area-Partial Paths - enable theming views associated with a module based on the route

            // Layout Paths - no-op because LayoutViewEngine uses multi-pass instead of layout paths
            // View Paths - no-op because LayoutViewEngine relies entirely on Partial view resolution
            // Partial Paths - 
            //   {area}/{controller}/

            // for "routed" request views...
            // enable /Views/{area}/{controller}/{viewName}

            // enable /Views/{partialName}
            // enable /Views/"DisplayTemplates/"+{templateName}
            // enable /Views/"EditorTemplates/+{templateName}
            var partialViewLocationFormats = new[] {
                parameters.VirtualPath + "/Views/{0}.cshtml",
                parameters.VirtualPath + "/Views/{1}/{0}.cshtml",
            };

            //Logger.Debug("PartialViewLocationFormats (theme): \r\n\t-{0}", string.Join("\r\n\t-", partialViewLocationFormats));

            var areaPartialViewLocationFormats = new[] {
                parameters.VirtualPath + "/Views/{2}/{1}/{0}.cshtml",
            };

            //Logger.Debug("AreaPartialViewLocationFormats (theme): \r\n\t-{0}", string.Join("\r\n\t-", areaPartialViewLocationFormats));

            var viewEngine = new RazorViewEngine {
                MasterLocationFormats = DisabledFormats,
                ViewLocationFormats = DisabledFormats,
                PartialViewLocationFormats = partialViewLocationFormats,
                AreaMasterLocationFormats = DisabledFormats,
                AreaViewLocationFormats = DisabledFormats,
                AreaPartialViewLocationFormats = areaPartialViewLocationFormats,
                ViewLocationCache = new ThemeViewLocationCache(parameters.VirtualPath),
            };

            return viewEngine;
        }
Пример #29
0
        protected void Application_Start()
        {
            //HostingEnvironment.RegisterVirtualPathProvider(new MongoVirtualPathProvider());
            AreaRegistration.RegisterAllAreas();

            AutoMapperWebConfiguration.Configure();

            WebApiConfig.Register(GlobalConfiguration.Configuration);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);

            ViewEngines.Engines.Clear();

            var nustache = new Nustache.Mvc.NustacheViewEngine();
            ViewEngines.Engines.Add(nustache);

            var razor = new RazorViewEngine();
            ViewEngines.Engines.Add(razor);
        }
Пример #30
0
        public static void Register()
        {
            System.Web.Mvc.RazorViewEngine rve = ( RazorViewEngine )ViewEngines.Engines
                                                 .FirstOrDefault(e => e.GetType() == typeof(RazorViewEngine));

            string[] additionalPartialViewLocations =
            {
                "~/src/Views/{1}/{0}.cshtml",
                "~/src/Views/{1}/{0}.vbhtml",
                "~/src/Views/Shared/{0}.cshtml",
                "~/src/Views/Shared/{0}.vbhtml"
            };


            if (rve != null)
            {
                rve.ViewLocationFormats = rve.ViewLocationFormats
                                          .Union(additionalPartialViewLocations)
                                          .ToArray();
            }
        }
Пример #31
0
        public static string RenderViewToString(string controllerName, string viewName, object model)
        {
            ViewDataDictionary viewData = new ViewDataDictionary();
            viewData.Model = model;
            var context = HttpContext.Current;
            var contextBase = new HttpContextWrapper(context);
            var routeData = new RouteData();
            routeData.Values.Add("controller", controllerName);

            var controllerContext = new ControllerContext(contextBase, routeData, new EmptyController());

            var razorViewEngine = new RazorViewEngine();
            var razorViewResult = ViewEngines.Engines.FindView(controllerContext, viewName, string.Empty);

            var writer = new StringWriter();
            var viewContext = new ViewContext(controllerContext, razorViewResult.View, new ViewDataDictionary(viewData), new TempDataDictionary(), writer);
            razorViewResult.View.Render(viewContext, writer);
            razorViewResult.ViewEngine.ReleaseView(controllerContext, razorViewResult.View);

            return writer.ToString();
        }