9

In the _ViewStart.cshtml there's this code:

@{ 
Layout = "~/Views/Shared/_Layout.cshtml";
}

Which makes every view page imports it. What do I have to do when I don't want the page to load the Layout.cshtml on it's view at all? I only want to do it on SOME pages, not all of them.

Pelicer
  • 1,348
  • 4
  • 23
  • 54

3 Answers3

13

On those views, set the layout to null (or another layout).

  • You can even do it conditionally, checking for a certain value or parameter and setting it to null if appropriate. – Daniel Aug 24 '17 at 14:04
8
@{
       Layout = null;
}

add above code to the view (the one you don't want to show default layout).

M--
  • 25,431
  • 8
  • 61
  • 93
5

If you're using visual studio, when you're adding a view, you should get a screen where you can enter all your data about the view including a checkbox for "Use a layout page". Just uncheck it and there you go.

If you're not or you just want to do it yourself, all it really does it just put the following at the top of your view:

@{
    Layout = null;
}

Hope this helps!

Bacskay
  • 396
  • 4
  • 12