亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

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

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

IViewLocationExpander API

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

項(xiàng)目目錄如下所示

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

所以我通過(guò)實(shí)現(xiàn)IViewLocationExpander進(jìn)行擴(kuò)展添加我自定義視圖路徑規(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 注冊(cè)

 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通過(guò)IViewLocationExpander擴(kuò)展視圖搜索路徑的實(shí)現(xiàn)的文章就介紹到這了,更多相關(guān)ASP.NET Core MVC 擴(kuò)展視圖搜索路徑內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評(píng)論