user1017882
user1017882

Reputation:

Bad practice to set layout to null?

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!)

Upvotes: 2

Views: 1494

Answers (1)

Brian Mains
Brian Mains

Reputation: 50728

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.

Upvotes: 6

Related Questions