cs0815
cs0815

Reputation: 17388

How to override the layout defined in _ViewStart for certain views in ASP.NET MVC 3?

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?

Upvotes: 16

Views: 16614

Answers (2)

ssilas777
ssilas777

Reputation: 9804

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

Upvotes: 33

serge.karalenka
serge.karalenka

Reputation: 990

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

@{
    Layout = null;
}

<!DOCTYPE html>
...

Upvotes: 3

Related Questions