15

Is it possible to suppress the layout expressed in _ViewStart.cshtml using ASP.NET MVC 3 for certain views of an app.

I understand that I can define the layout programmatically in the controller action. Maybe passing in "" achieves that?

rae1
  • 6,066
  • 4
  • 27
  • 48
cs0815
  • 16,751
  • 45
  • 136
  • 299

2 Answers2

33

You have two options

1) Use return PartialView() from controller, it won't take Layout from View start

2) Assign Layout = null,

 @{
     Layout = null;
  }

Check-out this interesting discussion and answer by marcind around this subject

Community
  • 1
  • 1
ssilas777
  • 9,672
  • 4
  • 45
  • 68
  • Can you also overwrite it with another layout? I'm on a specific page and I want to say `Layout = "Other layout than the one in view start"` ? Will it work? – Daniel May 28 '21 at 22:37
3

In order not to apply a layout, just assign null to the Layout property in your view:

@{
    Layout = null;
}

<!DOCTYPE html>
...
serge.karalenka
  • 980
  • 1
  • 15
  • 29