// internal for tests internal IEnumerable<string> GetViewLocationFormats(ViewLocationExpanderContext context) { if (!string.IsNullOrEmpty(context.AreaName) && !string.IsNullOrEmpty(context.ControllerName)) { return _options.AreaViewLocationFormats; } else if (!string.IsNullOrEmpty(context.ControllerName)) { return _options.ViewLocationFormats; } else if (!string.IsNullOrEmpty(context.AreaName) && !string.IsNullOrEmpty(context.PageName)) { return _options.AreaPageViewLocationFormats; } else if (!string.IsNullOrEmpty(context.PageName)) { return _options.PageViewLocationFormats; } else { // If we don't match one of these conditions, we'll just treat it like regular controller/action // and use those search paths. This is what we did in 1.0.0 without giving much thought to it. return _options.ViewLocationFormats; } }
从此处可以看出,它是通过判断 区域名称和控制器名称 是否都不为空,以此来判断客户端访问的到底是区域还是非区域。
文章最后我们通过调试来看下AreaViewLocationFormats 和ViewLocationFormats 的初始值:
至此本文就全部介绍完了,如果觉得对您有所启发请记得点个赞哦!!!
Demo源码:
链接: https://pan.baidu.com/s/1gn4JQTzn7hQLgfAtaUPDLg
提取码: mjgr
到此这篇关于ASP.NET Core MVC 修改视图的默认路径及其实现原理的文章就介绍到这了,更多相关ASP.NET Core MVC 视图路径内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!
您可能感兴趣的文章: