在MVC 1 中
1 private string GetPath(ControllerContext controllerContext, string[] locations, string locationsPropertyName, string name, string controllerName, string cacheKeyPrefix, bool useCache, out string[] searchedLocations) { 2 searchedLocations = _emptyLocations; 3 4 if (String.IsNullOrEmpty(name)) { 5 return String.Empty; 6 } 7 8 if (locations == null || locations.Length == 0) { 9 throw new InvalidOperationException(String.Format(CultureInfo.CurrentUICulture, 10 MvcResources.Common_PropertyCannotBeNullOrEmpty, locationsPropertyName)); 11 } 12 13 bool nameRepresentsPath = IsSpecificPath(name); 14 string cacheKey = CreateCacheKey(cacheKeyPrefix, name, (nameRepresentsPath) ? String.Empty : controllerName); 15 16 if (useCache) { 17 string result = ViewLocationCache.GetViewLocation(controllerContext.HttpContext, cacheKey); 18 if (result != null) { 19 return result; 20 } 21 } 22 23 return (nameRepresentsPath) ? 24 GetPathFromSpecificName(controllerContext, name, cacheKey, ref searchedLocations) : 25 GetPathFromGeneralName(controllerContext, locations, name, controllerName, cacheKey, ref searchedLocations); 26 }
在MVC 2,3 中
1 private string GetPath(ControllerContext controllerContext, string[] locations, string[] areaLocations, string locationsPropertyName, string name, string controllerName, string cacheKeyPrefix, bool useCache, out string[] searchedLocations) { 2 searchedLocations = _emptyLocations; 3 4 if (String.IsNullOrEmpty(name)) { 5 return String.Empty; 6 } 7 8 string areaName = AreaHelpers.GetAreaName(controllerContext.RouteData); 9 bool usingAreas = !String.IsNullOrEmpty(areaName); 10 List<ViewLocation> viewLocations = GetViewLocations(locations, (usingAreas) ? areaLocations : null); 11 12 if (viewLocations.Count == 0) { 13 throw new InvalidOperationException(String.Format(CultureInfo.CurrentUICulture, 14 MvcResources.Common_PropertyCannotBeNullOrEmpty, locationsPropertyName)); 15 } 16 17 bool nameRepresentsPath = IsSpecificPath(name); 18 string cacheKey = CreateCacheKey(cacheKeyPrefix, name, (nameRepresentsPath) ? String.Empty : controllerName, areaName); 19 20 if (useCache) { 21 return ViewLocationCache.GetViewLocation(controllerContext.HttpContext, cacheKey); 22 } 23 24 return (nameRepresentsPath) ? 25 GetPathFromSpecificName(controllerContext, name, cacheKey, ref searchedLocations) : 26 GetPathFromGeneralName(controllerContext, viewLocations, name, controllerName, areaName, cacheKey, ref searchedLocations); 27 }
在MVC 1 中的红色部分和在MVC 2,3 中的红色部分不一样呢,我怎么觉得在MVC 1 中红色部分更好呢。那位大哥大姐能指点下为什么要改成MVC 2,3这样呢?