Single-statement control-flow statements in Razor documents statements cannot contain markup 错误?

Single-statement control-flow statements in Razor documents statements cannot contain markup error?

出现以下错误:

Single-statement control-flow statements in Razor documents statements cannot contain markup. Markup should be enclosed in "{" and "}".

我正在构建 ASP.NET CORE 5 项目,但出现此错误。 我不明白这是什么错误。有没有人可以帮忙?

我试着为你搜索最有说服力的博客或文章。

为什么我之前的评论建议删除一些文件夹 re-running IDE 是因为我们之前也遇到过这个问题。我认为 Rick Strahl 的博客描述的是我们在这个 post 中的问题。当我们只编译时,应该不会遇到上面的错误。

Fixing Visual Studio Intellisense Errors

当然,用VS2022重新打开,问题就消失了。