0

I have 2 layout pages, One is a Master layout. This has basic layout that all my pages will use whether a user is logged in or not. The other is what i have called an Authorised layout, which is a layout view for users that are logged into the application. the Authorised layout view is rendered within the body of the Master layout and all my pages which require users to login are rendered within the body of the Authorised layout.

Now my question is how do I use the render section from the Master layout in the a child layout such as Home Page (for logged in user), i am not able to right now because the Master layout is not a direct master of the child views, it is a master of the Authorised layout which is the layout of the child view.

This is all in .NET CORE by the way

floormind
  • 1,868
  • 5
  • 31
  • 85

2 Answers2

0

I don't think you can have a layout render within a layout. But an alternative approach that may work well for you is as follows:

Create two layouts, one that is for non-authorized visitors and one that is for authorized visitors. For all the aspects of the two layouts that are the same, create view components. Then use these view components on the two layouts. That way all common html and logic is in just one place.

Then you can select the proper layout to use for the view based on whether the visitor is authenticated or not.

I use a very similar approach for my website work.

RonC
  • 31,330
  • 19
  • 94
  • 139
0

Are you looking for something along these lines:

// Master.cshtml
@RenderBody()

// AuthorizedLayout.cshtml
@{
    Layout = "Master";
}
@RenderBody()

// AuthorizedPage.cshtml
@{
    Layout = "AuthorizedLayout";
}

...

Pranav
  • 543
  • 4
  • 9