Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Sunday, April 10, 2011 10:17 AM
Hi,
I am working on WebMatrix Samples on using Layout and Razor Syntaxe. Unfortunatly I have an CS0103 Server error when a run the site that says that "The name 'Layout' does not exist inthe current context.
The sample is very easy. Two files, Index.cshtml and _Layout.cshtml in the same directory.
The "_Layout.cshtml" content is:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>My WebSite</title>
</head>
<body>
@RenderBody()
</body>
</html>
And the "index.cshtml" centent is:
@{
Layout = "~/_Layout.cshtml";
}
<h4>Hello World!</h4>
<h4>Hello World!</h4>
<h4>Hello World!</h4>
The error occurse on the line 2 of the index.cshtml file.
I tred to use Layout = "_Layout.cshtml" but without success. So can you please help me with this issue.
For information :
- OS = Windows 7 Enterprise
Applications that are installed
- Office Enterprise 2007
- Visual Studio 2010 Professional
- .Net Framework 4.0
- IE 9.0
- WebMatrix BETA
Regard, MehdiH
All replies (4)
Sunday, April 10, 2011 2:31 PM âś…Answered
Applications that are installed
....
WebMatrix BETA
That's your problem. "LayoutPage" was changed to simply "Layout" in Beta 2, which came out in October. The current samples and tutorials are all based on the RTM version which was released in January. Is there any reason why you cannot download the RTM version?
Sunday, April 10, 2011 12:32 PM
you pass the Layout = "~/_Layout.cshtml"; who trying to find out the layout page in main directory instead of where you place. you need to change them to
Layout = "~/Views/Shared/_LayoutPage.cshtml";
after doing that it's work if not you need to be sure that a views exist in Views directory called _ViewStart.cshtml should have valid layout perhaps your application never work.
Sunday, April 10, 2011 12:35 PM
Hi,
It's me again , I found a solution by replacing 'Layout' with 'LayoutPage'. it's work but I don't know way :(
So for me, the correct syntaxe is :
@{
** LayoutPage = "~/_Layout.cshtml" ;**
** }**
Sunday, April 10, 2011 12:44 PM
OK you are right but are you know that you have MVC 3 beta not the version RTM. so most of feature are not finialize or not work properly. for getting MVC 3 go to http://www.microsoft.com/web/gallery/install.aspx?appid=MVC3
the problem is nothing here but whenever you deploy this project to MVC 3 installed server. it's cause error who you never know at the time what's happened because you know that it's working on my system. so maybe confused you have.
well i know you already tell in post that sample application.