Suppose I have a .net 5.0 website that has both Razor pages and MVC pages.
That is, in Startup.Configure, I have:
app.UseEndpoints(endpoints =>
{
endpoints.MapRazorPages();
endpoints.MapControllers();
endpoints.MapControllerRoute("default", "{controller=Home}/{action=Index}");
});
And I have some pages like:
- /Pages/MyRazorPage.cshtml
- /Pages/MyRazorPage.cshtml.cs
And others like:
- /Controllers/MyMvcController.cs
- /Views/MyMvc/Index.cshtml
Is there a way to have them use the same layout?
It seems simple enough to create a Razor layout in /Pages/Shared/_Layout.cshtml and another in /Views/Shared/_Layout.cshtml, but if you want to have identical layouts for both types of pages, this seems a violation of the Don't Repeat Yourself principle.
Is there a way of sharing a single layout between both types of page?
Just as a followup - copying /Pages/Shared/_Layout.cshtml to /Views/Shared/_Layout.cshtml (and making sure /Views/_ViewStart.cshtml is set) works, except that the asp-page helpers don't work. Setting the URLs with plain href= works fine.