See #7200
Feedback on a related issue from Slack chat @ctolkien, @poke, and @TheSamsterZA ...
RE: Mixing MVC and RP in the same app, the RP guidance implies not to use a common layout page. The MVC guidance is a bit more helpful in regard to specifying the path in _ViewStart.cshtml, which implies that the layout can be anywhere (e.g., in Pages/Shared).
poke
... I often end up with both controllers _and_ Razor Pages, which is a mess because I want to share the layout (not copy it), although that’s not “recommended”, so I end up having to specify full paths for layouts everywhere. It’s a bit annoying.
sameer.singh
Sounds like there's a "Don't cross the streams" lesson in there somewhere. :thinking:
poke
There is! They don’t recommend you to mix layouts or components; but in reality, you usually want to share that.
chadt
We've shared layout and pages/mvc before too.... it works... doesn't feel too broken to me :slightly_smiling_face:
poke
Yeah, sharing it is not broken, but the official stance is that one should not do that I think. At least the docs said that in the past.
@rynowak what's the story on MVC and RP sharing layout?
@danroth27 @davidfowl @rynowak what's the story on MVC and RP sharing layout? This question comes up frequently.
Razor Pages will pickup the layout from the Views/Shared folder.
... and MVC will pick up a layout from the Pages/Shared folder?
If so, should we recommend one place or the other in a mixed app, or should we say that it's up to the dev to decide based on their personal preference?
and MVC will pickup a layout from the Pages/Shared folder?
No I don't believe so. @pranavkm could you please confirm?
Test case 1: Default MVC template with a Pages/Test.cshtml:
Layout from Views/Shared/_Layout.cshtml is picked up if the page has a Layout = "_Layout"; or if there’s a Pages/_ViewStart.cshtml with that line.
Test case 2: Default Razor Page template with a Controllers/TestController.cs and Views/Test/Index.cshtml.
Layout from Pages/Shared/_Layout.cshtml is picked up if the view has a Layout = "_Layout"; or if there’s a Views/_ViewStart.cshtml with that line.
So apparently designs are shared between both Razor pages and MVC.
If there’s both a layout in Views and Pages, then MVC will use the one from the Views directory, and Razor pages will use the one from the Pages directory.
Ty @poke ... case of :beer: to u for that one! That's what we needed to know (we'd have looked if only we had the time to check 🏃🏃🏃😅).
The menu layout is implemented in the Pages/Shared/_Layout.cshtml file.
Most helpful comment
Ty @poke ... case of :beer: to u for that one! That's what we needed to know (we'd have looked if only we had the time to check 🏃🏃🏃😅).