Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 347
Zote Avatar asked May 03 '11 13:05

Zote


Video Answer


1 Answers

@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.

like image 120
SLaks Avatar answered Sep 22 '22 11:09

SLaks