3

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?

user1929393
  • 4,089
  • 7
  • 30
  • 48
  • Do you have some code or example? – hackp0int Aug 02 '13 at 21:59
  • possible duplicate of [MVC 3: How to render a view without its layout page?](http://stackoverflow.com/questions/5318385/mvc-3-how-to-render-a-view-without-its-layout-page) – wal Aug 02 '13 at 22:03

3 Answers3

4

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.

Jay
  • 6,224
  • 4
  • 20
  • 23
3

All you have to do is explicitly set layout to null.

@{ Layout = null; }
Erik Funkenbusch
  • 92,674
  • 28
  • 195
  • 291
1

Put this in the header of the view

@{ Layout = null; }

Or something like that

Tamim Al Manaseer
  • 3,554
  • 3
  • 24
  • 33