简体   繁体   English

编译器错误消息:CS1525:无效的表达式术语“}”

[英]Compiler Error Message: CS1525: Invalid expression term '}'

I have this piece of code which gives me the error: "Compiler Error Message: CS1525: Invalid expression term '}'"我有这段代码给了我错误:“编译器错误消息:CS1525:无效的表达式术语'}'”

The error indicates the closing braces in line 69:错误指示第 69 行中的右大括号:

Line 67:                                                 @ibItem.ToString()
Line 68:                                                 @ibCount++
Line 69:                                             }
Line 70:                                         </div>
Line 71:                                         <!-- Carousel nav -->

Code:代码:

@{int ibCount = 0;}
@foreach (var ibItem in Model.imagePath)
{
       @ibItem.ToString()
       @ibCount++
}

Can someone help me to solve the issue?有人可以帮我解决这个问题吗? Thanks!谢谢!

I guess you want to print the ibItem to the view and increment ibCount. 我想你想要将ibItem打印到视图并增加ibCount。 in this case the @ symbol is not necessary as you're into the foreach loop and you haven't write any markup, so razor thinks he is still inside a "code" statement, so the @ is redundant. 在这种情况下,@ symbol不是必需的,因为你进入foreach循环并且你没有写任何标记,所以razor认为他仍然在“代码”语句中,所以@是多余的。 of course, since now ibCount is code, you need the semicolon at the end of the line. 当然,既然现在ibCount是代码,你需要在行尾添加分号。

@{int ibCount = 0;}
@foreach (var ibItem in Model.imagePath)
{
   ibCount++;
   @ibItem.ToString()

}

if you want instead to write the count too, i'd suggest to do the following (cover the value with brackets) 如果你想要编写计数,我建议做以下(用括号覆盖值)

@{int ibCount = 0;}
@foreach (var ibItem in Model.imagePath)
{

   @ibItem.ToString()
   @(ibCount++)

}

a good reference is the following: 一个很好的参考如下:

http://haacked.com/archive/2011/01/06/razor-syntax-quick-reference.aspx/ http://haacked.com/archive/2011/01/06/razor-syntax-quick-reference.aspx/

You're missing semicolons. 你丢失了分号。 It points to the end brace because that character is invalid, it needs to be either another component of an expression or the end of an expression. 它指向结束括号,因为该字符无效,它需要是表达式的另一个组件或表达式的结尾。

@{int ibCount = 0;}
@foreach (var ibItem in Model.imagePath)
{
       @ibItem.ToString();
       @ibCount++;
}

A similar issue I have found during the Web.config transformation.我在 Web.config 转换过程中发现了一个类似的问题。 The below error is showing Severity Code Description Project File Line Suppression State Error CS1525 Invalid expression term '<' AgencyAdmin2 C:\AcuityBrandAllcode\AgencyAdmin2\as-con-agencyadmin2\src\AgencyAdmin2\AgencyAdmin2\Web.Dev.Compiled.config 1 The below error is showing Severity Code Description Project File Line Suppression State Error CS1525 Invalid expression term '<' AgencyAdmin2 C:\AcuityBrandAllcode\AgencyAdmin2\as-con-agencyadmin2\src\AgencyAdmin2\AgencyAdmin2\Web.Dev.Compiled.config 1
Active.积极的。 I have resolved this issue by going to properties make build Action to content.我已经通过转到属性使构建动作到内容解决了这个问题。

enter image description here在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM