0
votes

I am getting compilation error in the code below, it complaining about a bracket but all the bracket and matching up I am a bit lost can someone please help me here thank in advance.

Error:

Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: CS1513: } expected

@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++) {

       <text> @Model[i].QuestionAsk  </text> <br />
        
        var s = @Model[i].PossibleAnswer;
        string[] exAns = s.Split(',');
 
        foreach( var singleAns in exAns){
         <text>singleAns</text> <br />
         @Html.RadioButtonFor(M =>M[i].UserAnsResponse, singleAns); <br />
        }

        <br />
    }
  
  <input type="submit" name="submit" />
}  
</body>
1
@MattBodily I doubt the <br/> is an issue as Razor will recognize these as HTML tags: dotnetfiddle.net/JVNiVu - AaronLS
even if i remove all the HTML tag is still complaining about the closing braket - Milas
I'd go with process of elimination, comment out all but bare necesities of the outer form, text, uncomment next loop, test, uncomment lines inside loop, test, uncomment inner loop, text, etc. until you find the line that is causing the error. Sometimes the errors in Razor are misleading. - AaronLS
i try this approach elimanation bit by bit, as soon there is a condition inside the for loop like eg an if condition, or another foreach condition it throwing a compilation error - Milas
You have an if condition? That's not shown in the code you posted, so hard to say. There's lots of little ways to get tripped up on Razor syntax. Depending on where it is, you may have a @ where it is or is not required, or mismatch braces on the if. - AaronLS

1 Answers

2
votes

Your error is in the assignment of the s variable, please see fixed code below. You also have unnecessary <text> tags and extra semicolons. I suggest you read up a little bit on Razor syntax.

@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>