How to specify the view location in asp.net core mvc when using custom locations?

前端 未结 8 2171
死守一世寂寞
死守一世寂寞 2020-11-30 22:59

Let\'s say I have a controller that uses attribute based routing to handle a requested url of /admin/product like so:



        
8条回答
  •  时光说笑
    2020-11-30 23:50

    I am using core 3.1 and just do this inside of ConfigureServices method inside of Startup.cs.

     services.AddControllersWithViews().AddRazorOptions(
         options => {// Add custom location to view search location
             options.ViewLocationFormats.Add("/Views/Shared/YourLocation/{0}.cshtml");                    
         });
    

    the {0} is just a place holder for the view name. Nice and simple.

提交回复
热议问题