Can the _Layout.cshtml (Master Page) render without views?

49 Views Asked by At

I was working on designing a layout and wanted to test how it looks and functions without having a specific view linked to it. Specifically, I wanted to see the _Layout.cshtml (Master Page) itself rendered without any views using it. However, I encountered difficulties as it seemed that the layout required a view to be associated with it.

So I decided to run the code in vscode instead of visual studio . Is it possible to render the master page without views?

I tried to test the rendering of the _Layout.cshtml (Master Page) without any specific views linked to it. I wanted to see how the layout looks and functions independently, without being associated with any particular view. I was expecting to view the master layout itself without any content from views.

1

There are 1 best solutions below

0
Mike Brind On

It is not possible to render a layout on its own because you cannot navigate directly to a layout file. If you add an @page directive to a layout to generate a route to it, it will not support the call to RenderBody() and is therefore no longer a layout.

If you want to test a layout in a browser, render an empty view.