Reputation: 4267
I'm trying to reference a view, but do not want all the header and footer that comes with the view because the viewstart references layout page. When I have a popup, it also shows the menu items in the header. Is there a way not to include the layout.cshtml?
Upvotes: 3
Views: 2179
Reputation: 3724
Put this in the header of the view
@{ Layout = null; }
Or something like that
Upvotes: 1
Reputation: 93424
All you have to do is explicitly set layout to null.
@{ Layout = null; }
Upvotes: 3
Reputation: 6294
Layouts can be specified directly in the view or based on the caller.
For example if your ActionMethod
returns like this:
return View();
The view will be rendered with the layout. However if the ActionMethod
returns like this:
return PartialView();
Then the rendered view will not have a layout.
However, this can be overridden in the view itself. In your view, if ViewBag.Layout
is null the layout will not be included. Inversely, if ViewBag.Layout
has a value that layout will be used, reguardless of how the view is called. For this reason, most views do not set ViewBag.Layout
directly, and leave it up the the caller to specify the intent.
Hope his helps.
Upvotes: 4