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

ASP.NET Core MVC通過IViewLocationExpander擴展視圖搜索路徑的實現(xiàn)

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

IViewLocationExpander API

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

項目目錄如下所示

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

所以我通過實現(xiàn)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

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

相關(guān)文章

最新評論

孟州市| 湖南省| 奉节县| 枞阳县| 万盛区| 北碚区| 郸城县| 石台县| 农安县| 屯留县| 新竹县| 景东| 辽中县| 新丰县| 淮北市| 浑源县| 白玉县| 道孚县| 亳州市| 淳化县| 浏阳市| 二连浩特市| 临城县| 年辖:市辖区| 道孚县| 连云港市| 论坛| 安顺市| 靖安县| 赞皇县| 安乡县| 海伦市| 若尔盖县| 安溪县| 石家庄市| 雷波县| 合水县| 临沭县| 红河县| 庄河市| 淅川县|