最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

ASP.NET Core MVC通過IViewLocationExpander擴展視圖搜索路徑的實現

 更新時間:2020年04月07日 09:05:35   作者:HueiFeng  
這篇文章主要介紹了ASP.NET Core MVC通過IViewLocationExpander擴展視圖搜索路徑的實現,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧

IViewLocationExpander API

  • ExpandViewLocations Razor視圖路徑,視圖引擎會搜索該路徑.
  • PopulateValues 每次調用都會填充路由

項目目錄如下所示

創(chuàng)建區(qū)域擴展器,其實我并不需要多區(qū)域,我目前只需要達到一個區(qū)域中有多個文件夾進行存放我的視圖.

所以我通過實現IViewLocationExpander進行擴展添加我自定義視圖路徑規(guī)則即可正如下代碼片段

 public class MyViewLocationExpander : IViewLocationExpander
  {
    public IEnumerable<string> ExpandViewLocations(ViewLocationExpanderContext context, IEnumerable<string> viewLocations)
    {
      if (context.ControllerName != null && context.ControllerName.StartsWith("App"))
      {
        viewLocations = viewLocations.Concat(
          new[] { $"/Areas/sysManage/Views/App/{context.ControllerName}/{context.ViewName}{RazorViewEngine.ViewExtension}"
              });
        return viewLocations;
      }

      if (context.AreaName != "sysManage") return viewLocations;
      viewLocations = viewLocations.Concat(
        new[] { $"/Areas/sysManage/Views/System/{context.ControllerName}/{context.ViewName}{RazorViewEngine.ViewExtension}"
        });
      return viewLocations;
    }

    public void PopulateValues(ViewLocationExpanderContext context)
    {
    }
  }

在Startup.ConfigureServices 注冊

 public void ConfigureServices(IServiceCollection services) 
    { 
      services.Configure<RazorViewEngineOptions>(o => { 
        o.ViewLocationExpanders.Add(new MyViewLocationExpander()); 
      }); 
      services.AddMvc(); 
    } 
 app.UseEndpoints(endpoints =>
      {
        endpoints.MapRazorPages();
        endpoints.MapAreaControllerRoute(
          name: "sysManage", "sysManage",
          pattern: "{area:exists}/{controller=Home}/{action=Index}/{id?}");
      });

最終路由指向的還是

/SysManage/Controller/Action

到此這篇關于ASP.NET Core MVC通過IViewLocationExpander擴展視圖搜索路徑的實現的文章就介紹到這了,更多相關ASP.NET Core MVC 擴展視圖搜索路徑內容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!

相關文章

最新評論

宜城市| 铜梁县| 荔波县| 韶关市| 崇州市| 天津市| 泊头市| 太湖县| 神木县| 江都市| 秦安县| 韶关市| 兴山县| 九龙坡区| 兴国县| 喀喇沁旗| 东台市| 余干县| 封丘县| 旌德县| 长泰县| 和龙市| 基隆市| 武山县| 望城县| 海林市| 昌宁县| 揭东县| 鄢陵县| 青铜峡市| 巴楚县| 乳山市| 司法| 新泰市| 海原县| 巩义市| 孝感市| 启东市| 盖州市| 铁岭市| 富锦市|