private void ExtendRazorViewEngineUsedToLocateViews() { ViewEngines.Engines.Clear(); // Customize the View Engine to add a new location to look for Views (under the Presentation Folder): var engine = new ExtendedRazorViewEngine(); engine.AddMasterLocationFormat("~/Presentation/Views/{1}/{0}.cshtml"); engine.AddMasterLocationFormat("~/Presentation/Shared/{0}.cshtml"); engine.AddViewLocationFormat("~/Presentation/Views/{1}/{0}.cshtml"); engine.AddViewLocationFormat("~/Presentation/Views/Shared/{0}.cshtml"); engine.AddPartialViewLocationFormat("~/Presentation/Views/{1}/{0}.cshtml"); engine.AddPartialViewLocationFormat("~/Presentation/Shared/{0}.cshtml"); //Don't need to add the default locations as they are already in the new Engine by default... //engine.AddMasterLocationFormat("~/Views/{1}/{0}.cshtml"); //engine.AddMasterLocationFormat("~/Shared/{0}.cshtml"); //engine.AddViewLocationFormat("~/Views/{1}/{0}.cshtml"); //engine.AddViewLocationFormat("~/Views/Shared/{0}.cshtml"); //engine.AddPartialViewLocationFormat("~/Views/{1}/{0}.cshtml"); //engine.AddPartialViewLocationFormat("~/Shared/{0}.cshtml"); ViewEngines.Engines.Add(engine); // Now add the following to any App.ModuleN.Application assembly where you put the Views. // // < ItemGroup > // < EmbeddedResource Include = "Views/**/*.cshtml" /> // </ ItemGroup > }
protected void Application_Start() { AreaRegistration.RegisterAllAreas(); WebApiConfig.Register(GlobalConfiguration.Configuration); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); RouteConfig.RegisterRoutes(RouteTable.Routes); BundleConfig.RegisterBundles(BundleTable.Bundles); //自定义View ViewEngines.Engines.Clear(); ExtendedRazorViewEngine engine = new ExtendedRazorViewEngine(); engine.AddPartialViewLocationFormat("~/Areas/Common/Views/Shared/{0}.cshtml"); engine.AddPartialViewLocationFormat("~/Areas/Common/Views/Shared/{0}.vbhtml"); ViewEngines.Engines.Add(engine); //Model去除前后空格 ModelBinders.Binders.DefaultBinder = new TrimModelBinder(); //设置MEF依赖注入容器 MefConfig.RegisterMef(); //初始化DB DatabaseInitializer.Initialize(); //在项目第一运行就需要初始数,到后面数据有的就不需要了 }
protected void Application_Start() { AreaRegistration.RegisterAllAreas(); WebApiConfig.Register(GlobalConfiguration.Configuration); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); RouteConfig.RegisterRoutes(RouteTable.Routes); BundleConfig.RegisterBundles(BundleTable.Bundles); //自定义View ViewEngines.Engines.Clear(); ExtendedRazorViewEngine engine = new ExtendedRazorViewEngine(); engine.AddPartialViewLocationFormat("~/Areas/Common/Views/Shared/{0}.cshtml"); engine.AddPartialViewLocationFormat("~/Areas/Common/Views/Shared/{0}.vbhtml"); ViewEngines.Engines.Add(engine); //Model去除前后空格 ModelBinders.Binders.DefaultBinder = new TrimModelBinder(); //设置MEF依赖注入容器 MefConfig.RegisterMef(); String configfilename = AppDomain.CurrentDomain.SetupInformation.ConfigurationFile; RemotingConfiguration.Configure(configfilename); //初始化DB // DatabaseInitializer.Initialize(); }
protected void Application_Start() { //----------------------------------------------------------- ViewEngines.Engines.Clear(); ExtendedRazorViewEngine engine = new ExtendedRazorViewEngine(); engine.AddViewLocationFormat("~/Views/{1}/{0}.cshtml"); engine.AddViewLocationFormat("~/Views/{1}/{0}.vbhtml"); // Add a shared location too, as the lines above are controller specific engine.AddPartialViewLocationFormat("~/Views/Shared/Theme/{0}.cshtml"); engine.AddPartialViewLocationFormat("~/Views/Shared/Theme/{0}.vbhtml"); engine.AddPartialViewLocationFormat("~/Views/Shared/FormInputs/{0}.cshtml"); engine.AddPartialViewLocationFormat("~/Views/Shared/FormInputs/{0}.vbhtml"); engine.AddPartialViewLocationFormat("~/Views/Shared/Theme/AsideMenu/{0}.cshtml"); engine.AddPartialViewLocationFormat("~/Views/Shared/Theme/AsideMenu/{0}.vbhtml"); engine.AddPartialViewLocationFormat("~/Views/Shared/Theme/HeaderTopbarItems/{0}.cshtml"); engine.AddPartialViewLocationFormat("~/Views/Shared/Theme/HeaderTopbarItems/{0}.vbhtml"); ViewEngines.Engines.Add(engine); //----------------------------------------------------------- AreaRegistration.RegisterAllAreas(); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); RouteConfig.RegisterRoutes(RouteTable.Routes); BundleConfig.RegisterBundles(BundleTable.Bundles); }
protected void Application_Start() { AreaRegistration.RegisterAllAreas(); WebApiConfig.Register(GlobalConfiguration.Configuration); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); RouteConfig.RegisterRoutes(RouteTable.Routes); BundleConfig.RegisterBundles(BundleTable.Bundles); AuthConfig.RegisterAuth(); SetupControllerBuilderNamespaces(); SetupMetadataProviders(); SetupValidatorProviders(); //var models = ReflectionHelper.Instance.GetTypesFromAssembly("Pfizer.Web") // .Where(type => type.GetCustomAttributes(typeof (ValidatorAttribute), true).FirstOrDefault() != null) // .ToList(); //models.ForEach(type=>ModelBinders.Binders.Add(type, new StringModelBinder())); var engine = new ExtendedRazorViewEngine(); //engine.AddViewLocationFormat(string.Format("{0}.Proposal/Views/{0}.cshtml", area)); // Add a shared location too, as the lines above are controller specific engine.AddPartialViewLocationFormat("~/Areas/Common/Views/Shared/{0}.cshtml"); ViewEngines.Engines.Add(engine); }
protected void Setup_Templates() { ViewEngines.Engines.Clear(); ExtendedRazorViewEngine engine = new ExtendedRazorViewEngine(); engine.AddViewLocationFormat("~/Templates/{1}/{0}.cshtml"); // Add a shared location too, as the lines above are controller specific engine.AddPartialViewLocationFormat("~/Templates/{0}.cshtml"); ViewEngines.Engines.Add(engine); }