Zote
Zote

Reputation: 5379

Why does this code not remove Layout?

I spent some time trying to remove layout (defined in _ViewStart) using:

@Layout = ""

and

@Layout = null

Why does it only work using block?

@{
  Layout = "";
}

In my vision, both ways should work.

Upvotes: 12

Views: 4818

Answers (1)

SLaks
SLaks

Reputation: 887767

@Layout is a code nugget.
It prints the value of the Layout property.

The Razor parser stops at the space after the word Layout, so the = null is parsed as literal markup.

You want to execute a statement, not print a value, so you need to use a code block (@{ ... }).

For more information, see my blog post.

Upvotes: 15

Related Questions