The Razor MVC4 parser is different from MVC3. Razor v3 has advanced parser functions, and on the other hand, strict parsing is comparable to MVC3.
When converting MVC3 to MVC4, you may encounter a syntax error if you did not use razor syntaxes in the right way.
The solutions to some common razor code errors that are not allowed in Razor v2 are as follows:
-> Avoid using server blocks in views if there is no variable declaration section.
Don't : @{if(check){body}} Recommended : @if(check){body}
-> Avoid using @ when you are already in the server area.
Don't : @if(@variable) Recommended : @if(variable) Don't : @{int a = @Model.Property } Recommended : @{int a = Model.Property }
source share