Sdl.Web.Mvc/Configuration/BaseAreaRegistration.cs
/// <summary>
/// Automatically register all view models for an area. This is done by searching the file system
/// for all .cshtml files, determining the controller and view names from the path, and using the
/// BuildManager to determine the model type by compiling the view. Note that if your area contains
/// a lot of views, this can be a lengthy process and you might be better off explicitly registering
/// your views with the RegisterViewModel method
/// </summary>
Automatically register all view models for an area. This is done by searching the file system
for all .cshtml files, determining the controller and view names from the path, and using the
BuildManager to determine the model type by compiling the view. Note that if your area contains
a lot of views, this can be a lengthy process and you might be better off explicitly registering
your views with the RegisterViewModel method
Automatically register all view models for an area . This is done by searching the file system for all . cshtml files determining the controller and view names from the path and using the BuildManager to determine the model type by compiling the view . Note that if your area contains a lot of views this can be a lengthy process and you might be better off explicitly registering your views with the RegisterViewModel method
protected virtual void RegisterAllViewModels()
        {
            DateTime timer = DateTime.Now;
            int viewCount = 0;
            string baseDir = AppDomain.CurrentDomain.BaseDirectory;
            string path = Path.Combine(baseDir, "Areas", this.AreaName, "Views");
            Log.Debug("Staring to register views for area: {0}", this.AreaName);
            foreach (string file in Directory.GetFiles(path, "*.cshtml", SearchOption.AllDirectories))
            {
                string relativePath = file.Substring(path.Length + 1);
                string virtualPath = @"~/" + file.Replace(baseDir, string.Empty).Replace("\\", "/");
                int pos = relativePath.IndexOf("\\");
                if (pos > 0)
                {
                    string controller = relativePath.Substring(0, pos);
                    string view = relativePath.Substring(pos + 1);
                    int extnPos = view.LastIndexOf(".cshtml");
                    view = view.Substring(0, extnPos);
                    MvcData mvcData = new MvcData { AreaName = this.AreaName, ControllerName = controller, ViewName = view };
                    try
                    {
                        ModelTypeRegistry.RegisterViewModel(mvcData, virtualPath);
                        viewCount++;
                    }
                    catch
                    {
                    }
                }
                else
                {
                    Log.Warn("Cannot add view {0} to view model registry as it is not in a {ControllerName} subfolder", file);
                }
            }
            Log.Info("Registered {0} views for area {1} in {2} milliseconds. This startup overhead can be reduced by explicitly registering view using the Sdl.Web.Mvc.Configuration.BaseAreaRegistration.RegisterView() method.", viewCount, this.AreaName, (DateTime.Now - timer).TotalMilliseconds);
        }
protected virtual void RegisterAllViewModels ( ) { DateTime timer = DateTime . Now ; int viewCount = 0 ; string baseDir = AppDomain . CurrentDomain . BaseDirectory ; string path = Path . Combine ( baseDir , " " , this . AreaName , " " ) ; Log . Debug ( " " , this . AreaName ) ; foreach ( string file in Directory . GetFiles ( path , " " , SearchOption . AllDirectories ) ) { string relativePath = file . Substring ( path . Length + 1 ) ; string virtualPath = @"~/" + file . Replace ( baseDir , string . Empty ) . Replace ( " \\ " , " " ) ; int pos = relativePath . IndexOf ( " \\ " ) ; if ( pos > 0 ) { string controller = relativePath . Substring ( 0 , pos ) ; string view = relativePath . Substring ( pos + 1 ) ; int extnPos = view . LastIndexOf ( " " ) ; view = view . Substring ( 0 , extnPos ) ; MvcData mvcData = new MvcData { AreaName = this . AreaName , ControllerName = controller , ViewName = view } ; try { ModelTypeRegistry . RegisterViewModel ( mvcData , virtualPath ) ; viewCount ++ ; } catch { } } else { Log . Warn ( " " , file ) ; } } Log . Info ( " " , viewCount , this . AreaName , ( DateTime . Now - timer ) . TotalMilliseconds ) ; }
Automatically register all view models for an area.
Automatically register all view models for an area .
//Do nothing - we ignore views that are not strongly typed