Я следовал этим инструкциям здесь: http://w3schools.com/razor/razor_example.asp ПРИМЕЧАНИЕ: я использую Web Matrix
В примере сказано, что сделать это:
@
{
var imagePath;
if( Request["Choice"] != null)
{imagePath="images\" + Request["Choice"];}
}
<!DOCTYPE html>
<html>
<body>
<h1>Display Images</h1>
<form method="post" action="">
<div>
I want to see:
<select name="Choice">
<option value="Photo1.jpg">Photo 1</option>
<option value="Photo2.jpg">Photo 2</option>
<option value="Photo3.jpg">Photo 3</option>
</select>
<input type="submit" value="Submit" />
</div>
<div style="padding:10px;">
@if(imagePath != "")
{<img src="@imagePath" alt="Sample" />}
</div>
</form>
</body>
</html>
И все, что я получаю этоэта ошибка:
Нужно ли что-то настраивать, чтобы принимать @ {на отдельных линиях?
Server Error in '/' Application.
Parser Error
Description: An error occurred during the parsing of a resource
required to service this request. Please review the following
specific parse error details and modify your source file appropriately.
Parser Error Message: A space or line break was encountered after
the "@" character. Only valid identifiers, keywords, comments,
"(" and "{" are valid at the start of a code block and they must
occur immediately following "@" with no space in between.
Source Error:
Line 1: @
Line 2: {
Line 3: var imagePath;
Source File: /Page.cshtml Line: 1
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.1
Если я помещу их в одну строку, я получаю эту ошибку:
Parser Error
Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately.
Parser Error Message: The code block is missing a closing "}" character. Make sure you have a matching "}" character for all the "{" characters within this block, and that none of the "}" characters are being interpreted as markup.
Source Error:
Line 1: @{
Line 2: var imagePath;
Line 3: if( Request["Choice"] != null)
Source File: /Page.cshtml Line: 1
Я не знаю, что не так.