Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Pages/Shared layout in intro to RP #7336

Closed
Rick-Anderson opened this issue Jun 27, 2018 · 9 comments
Closed

Fix Pages/Shared layout in intro to RP #7336

Rick-Anderson opened this issue Jun 27, 2018 · 9 comments
Assignees
Milestone

Comments

@Rick-Anderson
Copy link
Contributor

See #7200

@guardrex
Copy link
Collaborator

guardrex commented Jun 27, 2018

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. 🤔

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 🙂

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.

@Rick-Anderson
Copy link
Contributor Author

@rynowak what's the story on MVC and RP sharing layout?

@Rick-Anderson
Copy link
Contributor Author

@danroth27 @davidfowl @rynowak what's the story on MVC and RP sharing layout? This question comes up frequently.

@danroth27
Copy link
Member

Razor Pages will pickup the layout from the Views/Shared folder.

@guardrex
Copy link
Collaborator

guardrex commented Jul 25, 2018

... 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?

@danroth27
Copy link
Member

and MVC will pickup a layout from the Pages/Shared folder?

No I don't believe so. @pranavkm could you please confirm?

@poke
Copy link
Contributor

poke commented Jul 25, 2018

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.

@guardrex
Copy link
Collaborator

Ty @poke ... case of 🍺 to u for that one! That's what we needed to know (we'd have looked if only we had the time to check 🏃🏃🏃😅).

@Rick-Anderson
Copy link
Contributor Author

The layout page

The menu layout is implemented in the Pages/Shared/_Layout.cshtml file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants