Razor View Without Layout

user156888 picture user156888 · Jul 7, 2011 · Viewed 111.2k times · Source

How come when I have Layout = null; in my view - it still pulls in the default layout?!

Is there some trick to stop it doing that?

Here is my view without layout:

@{
    Layout = "";
}

<!DOCTYPE html>

<html>
<head>
    <title>Index</title>
    @{Html.RenderAction("Head", "Header");}
</head>
<body>
    <div>
        Home
    </div>
</body>
</html>

Here is the rendered output!!

<!DOCTYPE html>

<html>
<head>
    <title>Index</title>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title></title>
    <link href="/Content/Site.css" rel="stylesheet" type="text/css" />
    <script src="/Scripts/jquery-1.5.1.min.js" type="text/javascript"></script>
    <script src="/Scripts/modernizr-1.7.min.js" type="text/javascript"></script>
</head>

<body>
    header
</body>
</html>
</head>
<body>
    <div>
        Home
    </div>
</body>
</html>

Answer

Jean-Baptiste HENRY picture Jean-Baptiste HENRY · Jul 16, 2013

I think this :

@{
    Layout = "";
 }

is not the same as this :

@{
    Layout = null;
 }

I use the second and it's working, no _Viewstart included.