Sven E. Thorsen - 483 - Feb 18, 2014

Have seen this error a few times, but this time I can’t seem to figure it out, even after a few hours of digging and trying.

Hi Sven, I see the VS issues, but does the page itself work? 

Note: if you’re using a  ‘@model’ it needs to be called via a service. 

Henrik Elkjær Hagen:

Don’t you need an @inherit before you can use @model?

No, ‘@model T’ is a just short hand for ‘@inherits ViewPage<T>’.

The reason why ‘@model’ has issues is that it’s not built into Razor by default, it’s an optional directive we have to implement in our user-space razor extensions. 

Sven E. Thorsen:

Using @inherits instead gets rid of the squiggly lines and the error :slight_smile:

And yes, the page works with @model also. Just no intellisense.

Yeah unfortunately that’s VS.NET’s MVC-coupled Razor intelli-sense for you.

Sven E. Thorsen:

BTW. Is there a reason that Layout = null and Layout = “” behave differently? The VS Razor template for ignoring _Layout.cshtml sets Layout = null, which still loads the _Layout.cshtml parent view.

Sorry what are you saying Layout="" does?

Sven E. Thorsen:

Say I have:
Views/_Layout.cshtml
<html>
<body>
@RenderBody()
</body>
</html>

Views/Logon/Logons.cshtml
@{
Layout = null;
}
<html>
<body>
<p>Here you can log in.</p>
</body>
</html>

The rendered result is:

<html>
<body>
<html>
<body>
<p>Here you can log in.</p>
</body>
</html>
</body>
</html>

If I set Layout = “” in Logons.cshtml, I get as expected:

<html>
<body>
<p>Here you can log in.</p>
</body>
</html>

Is there a reason Layout = null and Layout = “” produce different results?

Well Layout = null, suggests to use the default layout template, whilst Layout="" suggests to use none.

Sven E. Thorsen:

Aha, thanks :slight_smile: