0

It's my first time using the razor viewengine, could some one assist me? I get the following error: 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 foreach 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 12: <tr>
Line 13: 
Line 14: @foreach(string fieldName in Model.FieldNames) {
Line 15:         if(Model.FieldTypes[fieldName]=="label") {
Line 16:       @:  <td class="label" data-bind="text: @fieldName"></td>

My code is:

@foreach(string fieldName in Model.FieldNames) {
        if(Model.FieldTypes[fieldName]=="label") {
      @:  <td class="label" data-bind="text: @fieldName"></td>
        }
        else if(Model.FieldTypes[fieldName]=="text") {
      @:   <td class="text"><input type="text" data-bind="value: @fieldName, event: {focus: highlightField, blur: updateUser}"/></td>
        }
        else if(Model.FieldTypes[fieldName]=="number") {
     @:   <td class="number"><input type="text" data-bind="value: @fieldName, event: {focus: highlightField, blur: updateUser}"/></td>
        }
      else if(Model.FieldTypes[fieldName].Contains("dropdown") {
     @:   <td class="text"><select id='groupSelect' data-bind="options: @Model.FieldTypes[fieldName].Replace("dropdown", ""), optionsText: 'Name', selectedOptions: selectedUserGroupValue, event: {focus: highlightField, blur: updateUser}"></select>
        } 
     }

What's funny is it works perfectly if I comment out this last part:

@*
 else if(Model.FieldTypes[fieldName].Contains("dropdown") {
     @:   <td class="text"><select id='groupSelect' data-bind="options: @Model.FieldTypes[fieldName].Replace("dropdown", ""), optionsText: 'Name', selectedOptions: selectedUserGroupValue, event: {focus: highlightField, blur: updateUser}"></select>
        } 
*@

Anyone have any clue why adding this section causes this error?

Much appreciated.

4
  • If you could put the code in code syntax it would be greatly appreciated Jun 9, 2011 at 20:11
  • Note that you don't need the @: inside the if bodies
    – marcind
    Jun 9, 2011 at 21:08
  • What do you mean by code in code syntax?
    – pilavdzice
    Jun 9, 2011 at 21:40
  • When I took out the @: in the lines under each if and elseif it gave an error again... Any ideas what a good reference on razor syntax is? I googled it and got a page that covers just really basic examples.
    – pilavdzice
    Jun 9, 2011 at 21:43

2 Answers 2

2

The last if condition is missing a ")".

1
  • Thanks, wow I can't believe I missed that!
    – pilavdzice
    Jun 9, 2011 at 21:40
1

How about this?

@foreach (string fieldName in Model.FieldNames)
{
    if (Model.FieldTypes[fieldName] == "label")
    {
    }
    else if (Model.FieldTypes[fieldName] == "text")
    {
    }
    else if (Model.FieldTypes[fieldName] == "number")
    {
    }
    else if (Model.FieldTypes[fieldName].Contains("dropdown"))
    {
    }
}

Not the answer you're looking for? Browse other questions tagged or ask your own question.