This is a really weird error, I think it may be a razor bug. I'm using VS 2012, MVC4, Framework 4.5.
Following these instructions: http://www.asp.net/whitepapers/mvc4-release-notes#_Toc303253806 I created a new MVC4 project and then I copied all my code (controllers, views, viewmodels) to it from the MVC3 project.
Eveything worked just fine, until I tested one View which has a custom helper and inside it it has one foreach
, one switch
, three if
statements and then I call some other custom helpers in there too.
It's exactly the same code in both projects, in MVC3 it works, but in MVC4 it shows this message:
Compiler Error Message: CS1513: } expected
So I tried adding one curly bracket but it shows the same error, so I keep adding brackets and it won't stop telling me the same thing.
I googled this issue but I just found this question with no answer: http://www.1771.in/asp-net-mvc-4-issues-migrating-mvc3-view-in-vs-2012-rc.html
has anyone experienced this issue?
I ran into this "Expected }" issue as well and the culprit turned out to be an apostrophe in an HTML comment This seems like a bug in Razor.
Here is an example on how to reproduce this issue in the default MVC 4 application with VS 2012. Just add the following a comment with an apostrophe to the @section featured {} in the default.cshtml. Remove the apostrophe from the comment and it works OK.
I experienced this error but narrowed it down to a missing slash to close a tag. this worked in MVC3:
but not in MVC4. it requires this:
The Razor parser of MVC4 is different from MVC3. Razor v3 is having advanced parser features and on the other hand strict parsing compare to MVC3.
You may run into syntax error in view while converting MVC3 to MVC4 if you have not used razor syntaxes in correct manner.
Solution of some common razor code mistakes that are not allowed in Razor v2 are :
--> Avoid using server blocks in views unless there is variable declaration section.
--> Avoid using @ when you are already in server scope.
Most helpful thing to do that will solve 6/10 of these for you is in VS2012
File-> Source Control -> Advanced -> Format this Document.
This will solve any un-closed div's, conditional statements even ul's and li's which cause big errors for .net.
This may be more of a long shot but sometimes if you are using a keyword it will cause that error
List of Keywords VS 2012 http://msdn.microsoft.com/en-us/library/x53a06bb%28v=vs.110%29.aspx
I know two of the new keywords are await and async for 4.5
See the following for an example of what I am talking about http://www.wduffy.co.uk/blog/css-class-property-asp-net-mvc-htmlattributes/
I had exactly the same issue.
In Razor MVC3 i was accessing the vars like this: @vSuggestion but in MVC4 the @ is not necessary.
My example, i had this code in MVC3 working:
In MVC4, Razor wasn't catching the first curly bracket from the switch statement. So i removed the @ from @vSuggestion and razor parsed the code properly.
Hope it helps.