今天在写cshtml页面报错:
An error occurred during the compilation of a resource required to process this request. Please review the following specific error details and modify your source code appropriately.
Expected a "{" but found a "xxx". Block statements must be enclosed in "{" and "}". You cannot use single-statement control-flow statements in CSHTML pages. For example, the following is not allowed:
@if(isLoggedIn)
<p>Hello, @user</p>
Instead, wrap the contents of the block in "{}":
@if(isLoggedIn) {
<p>Hello, @user</p>
}
大概的中文意思是:
编译处理该请求所需的资源期间发生错误。请查看以下特定的错误详细信息,并适当地修改您的源代码。
E:\xxx \ Views \ Home \ ShowComment.cshtml
预期为“ {”,但找到了“ xxx”。块语句必须用“ {”和“}”括起来。您不能在CSHTML页面中使用单语句控制流语句。例如,不允许以下内容:@if(isLoggedIn)<p>您好,@user </ p>而是将块的内容包装在“ {}”中:@if(isLoggedIn){<p>您好, @user </ p>}
提示已经很明确了,就是在cshtml页面不能使用单语句控制,也是就if(条件)要用大括号{}.如:
@if(isLoggedIn) {
<p>Hello, @user</p>
}
以上就是【You cannot use single-statement control-flow statements in CSHTML pages】的全部内容了,欢迎留言评论进行交流!