MVC how to include a view that does not have layout information

advertisements

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?


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.