Rendering dynamics views in Razor (chtml), How to add a FileProvider to razor in asp.net core 3.0?

前端 未结 2 1758
执念已碎
执念已碎 2021-01-23 18:50

I am migrating from asp-net core 2.2 to asp-net core 3.0, I was using this block to define my File Class Provider, as you know this is used to create dynamic razor views (dynami

相关标签:
2条回答
  • 2021-01-23 19:08

    DavidG provided us the solution: (I have tested and it works).

    The solution is:

    services.AddControllersWithViews().AddRazorRuntimeCompilation(
        options => options.FileProviders.Add(new PhysicalFileProvider(appDirectory)));
    

    In this case:

    services.AddControllersWithViews().AddRazorRuntimeCompilation(
        options => options.FileProviders.Add(new MyCostumizedFileProvider()));
    
    0 讨论(0)
  • 2021-01-23 19:22

    For ASP.NET MVC Core 3, this is the way to add a file provider:

    services.AddControllersWithViews()
        .AddRazorRuntimeCompilation(options => options.FileProviders.Add(
            new PhysicalFileProvider(appDirectory)));
    
    0 讨论(0)
提交回复
热议问题