gpt4 book ai didi

asp.net-mvc-3 - 当我按照此示例操作时,为什么会出现解析器错误?

转载 作者:行者123 更新时间:2023-12-02 13:49:37 27 4
gpt4 key购买 nike

我按照以下说明进行操作: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>
&nbsp;
<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

我不知道出了什么问题。

最佳答案

有些人只需将 jquery.com 中的代码示例复制到 razor 文件中就会偶然发现这个答案。例如,我正在测试一些东西,并从一个长 JavaScript 变量值(特别是正则表达式)中得到了错误。

 emailRegex = /^[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/,

注意@@,我必须添加第二个@来转义....否则我会收到上面的错误,因此谷歌搜索会在顶部结果中显示这个stackoverflow页面。因此,虽然这不能直接回答问题,但我确信它可以帮助其他人。

关于asp.net-mvc-3 - 当我按照此示例操作时,为什么会出现解析器错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7252293/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com