public void ConfigureServices(IServiceCollection services)
{
services.AddControllersWithViews();
services.AddRazorPages();
services.AddDbContext<ProductDbContext>
(opts =>
{
opts.UseSqlServer(Configuration["ConnectionStrings:AppDataConnection"]);
});
services.AddHttpsRedirection(opts =>
{
opts.HttpsPort = 44350;
});
services.Configure<RazorViewEngineOptions>(opts=> {
opts.PageViewLocationFormats.Clear();
opts.PageViewLocationFormats.Add("/Pages/Shared/Layouts/{0}" + RazorViewEngine.ViewExtension);
});
}
I am configuring the RazorViewEngineOptions
in the ConfigureServices
method in Startup
to add additional entries to the PageViewLocationFormats
collection.
The program still searches only the default locations.
I cleared the list PageViewLocationFormats
list
opts.PageViewLocationFormats.Clear();
but the program still searches only the default locations and shows error:
An unhandled exception occurred while processing the request.
InvalidOperationException: The layout view ‘_Layout’ could not be located. The following locations were searched:/Views/Home/_Layout.cshtml
/Views/Shared/_Layout.cshtml
/Pages/Shared/_Layout.cshtml
Why is this not working? I am sure I did the same thing in previous versions and it used to work…
6