开发者

razor syntax question - where is the missing } in this? (I am using knockoutjs but I think that's unrelated, ignore that part) [closed]

开发者_StackOverflow中文版 This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. Closed 9 years ago.

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.


The last if condition is missing a ")".


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"))
    {
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜