razor syntax question - where is the missing } in this? (I am using knockoutjs but I think that's unrelated, ignore that part) [closed]
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"))
{
}
}
精彩评论