2

Is it bad practice to set the layout of an MVC view to null?

@{
    Layout = null;
}

<!DOCTYPE html>
<html>
<head>
</head>
<body>
// Some Content
</body>
</html>

By 'bad practice', I mean is anybody aware of inner-components of the MVC rendering engine that depend on a layout to be an instance of an object? Or is this a fine approach to specifying 'no layout'?

To Confirm

This approach works and gives me the result I'm after, I'm asking whether I could inadvertently cause headaches elsewhere in the system.

Apologies, I should've clarified - I am leveraging _ViewStart to set the layout, so this serves as an override (probably missed a key bit of the question out there sorry!)

  • 1
    how about removing @{ Layout = null; } if you don't want a layout? – Lidaranis Oct 07 '16 at 14:18
  • Remove the code `@{Layout = null;}` as suggested by @Lidaranis. It is not required. – G J Oct 07 '16 at 14:19
  • 1
    Setting the Layout explicitly to null might be necessary if you want to get rid of a standard layout defined in _ViewStart.cshtml. For example, if you want to render dialog contents using a parital view and they should not show the default menu. – Georg Patscheider Oct 07 '16 at 14:24

1 Answers1

6

I just created a new CSHTML view page (without a layout) and this was at the top:

@{
    Layout = null;
}

NULL means don't use a layout. So no, not bad practice and should have no consequence.

Brian Mains
  • 50,520
  • 35
  • 148
  • 257