Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-cloud-platform/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# razor中的whn循环编译错误_C#_Asp.net_Asp.net Mvc 3_Asp.net Mvc 4_Razor - Fatal编程技术网

C# razor中的whn循环编译错误

C# razor中的whn循环编译错误,c#,asp.net,asp.net-mvc-3,asp.net-mvc-4,razor,C#,Asp.net,Asp.net Mvc 3,Asp.net Mvc 4,Razor,我在下面的代码中遇到编译错误,它抱怨一个括号,但是所有的括号和匹配我有点迷路了,请有人在这里帮助我,提前感谢 错误: 描述:编译服务此请求所需的资源时出错。请查看以下特定错误详细信息,并适当修改源代码 编译器错误消息:CS1513:}应为 @使用System.Linq @使用系统 @使用System.Text @使用系统集合; @模型列表 @使用(Html.BeginForm(“GetMarks”、“问卷”)){ for(int i=0;iM[i].UserAnsResponse,singleA

我在下面的代码中遇到编译错误,它抱怨一个括号,但是所有的括号和匹配我有点迷路了,请有人在这里帮助我,提前感谢

错误:

描述:编译服务此请求所需的资源时出错。请查看以下特定错误详细信息,并适当修改源代码

编译器错误消息:CS1513:}应为

@使用System.Linq
@使用系统
@使用System.Text
@使用系统集合;
@模型列表
@使用(Html.BeginForm(“GetMarks”、“问卷”)){
for(int i=0;i
var s=@Model[i]。可能的答案;
字符串[]exAns=s.Split(',');
foreach(exAns中的var singleAns){
单身人士
@(M=>M[i].UserAnsResponse,singleAns);
}
} }
您的错误在于
s
变量的赋值,请参见下面的固定代码。您还有不必要的
标记和额外的分号。我建议你仔细阅读一下Razor的语法

@using System.Linq
@using System
@using System.Text
@using System.Collections;
@model List<PairingTest.Web.Models.QuestionnaireViewModel>

<html>
<head>
    <title></title>
</head>
<body>
@using (Html.BeginForm("GetMarks","Questionnaire")) {


    for(int i = 0;i < Model.Count;i++) {

        @Model[i].QuestionAsk <br />

        var s = Model[i].PossibleAnswer;
        string[] exAns = s.Split(',');

        foreach( var singleAns in exAns){
         @singleAns <br />
         @Html.RadioButtonFor(M =>M[i].UserAnsResponse, singleAns) <br />
        }

        <br />
    }

  <input type="submit" name="submit" />
}  
</body>
@使用System.Linq
@使用系统
@使用System.Text
@使用系统集合;
@模型列表
@使用(Html.BeginForm(“GetMarks”、“问卷”)){
for(int i=0;i
var s=模型[i]。可能的答案;
字符串[]exAns=s.Split(',');
foreach(exAns中的var singleAns){
@单身人士
@Html.radioButton(M=>M[i].UserAnsResponse,singleAns)
}
} }
@mattbool我怀疑

是一个问题,因为Razor会将这些标记识别为HTML标记:即使我删除了所有HTML标记,但仍在抱怨关闭的Braket,我会执行消除过程,注释掉外部表单、文本、取消注释下一个循环、测试、取消注释循环内的行、测试、,取消对内部循环、文本等的注释,直到找到导致错误的行。有时Razor中的错误是误导性的。我一点一点地尝试这种方法,只要for循环中有一个条件,比如if条件,或者另一个foreach条件,它就会抛出编译错误。你有一个
if
条件吗?这在你发布的代码中没有显示,很难说。有很多小方法会被Razor语法绊倒。根据位置的不同,您可能需要或不需要
@
,或者
上的大括号不匹配(如果
)。当我删除分号时,代码会显示错误并在粘贴的代码中查找分号look,您需要删除
@
,而不是
@Model[i]的code>。可能的答案
@using System.Linq
@using System
@using System.Text
@using System.Collections;
@model List<PairingTest.Web.Models.QuestionnaireViewModel>

<html>
<head>
    <title></title>
</head>
<body>
@using (Html.BeginForm("GetMarks","Questionnaire")) {


    for(int i = 0;i < Model.Count;i++) {

        @Model[i].QuestionAsk <br />

        var s = Model[i].PossibleAnswer;
        string[] exAns = s.Split(',');

        foreach( var singleAns in exAns){
         @singleAns <br />
         @Html.RadioButtonFor(M =>M[i].UserAnsResponse, singleAns) <br />
        }

        <br />
    }

  <input type="submit" name="submit" />
}  
</body>