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

Getting the following error:

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

enter image description here

I am building ASP.NET CORE 5 project and I get this error. I don't understand what error is this. Is there anyone who can help?



Solution 1:[1]

I try to search you the most persuasive blog or article for you.

Why my previous comment suggested deleting some folders and re-running the IDE is because we had this problem before too. I think what Rick Strahl's blog describes is our problem in this post. When we only compile, we should not encounter the above error.

Fixing Visual Studio Intellisense Errors

Of course, when you reopen it with VS2022, the problem will disappear.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Jason