Exception in AspnetMvc with Razor: Parser Error Message: Expected “}”.

The below text/error can occur if you have missed one of the } in jquery in a @section features{ section.

It can be hard tracking exactly which } is missing because commenting out the javascript code doesn’t change anything – it seems the razor engine doesn’t care about that type of comments.  Instead start the @section{} anew and copy-paste the code in again piece by piece.

In my case it was a totally ok javascript for loop:

for (i = 0 ; i < 12 ; i++) { }

Event though it is correct syntax it makes Razor fail.  Seems to be a bug in AspnetMVC/Razor/Dotnet4.5/Visualstudio11.
I am losing karma by not making the bug easy to reproduce and report the bug.

Server Error in ‘/myApplication’ Application. 

 

Parser Error 

Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately.

Parser Error Message: Expected “}”.

Source Error:

Line 204:        </p>

Line 205:    </section>

Line 206:</section>

 

Tags: , ,

5 Responses to “Exception in AspnetMvc with Razor: Parser Error Message: Expected “}”.”

  1. I’ve had this same bug. It is a crazy Razor bug.

  2. Prof says:

    Stupid Razor considers the “<" symbol as an opening angle bracket. We can fool him, closing brackets after comment:

    for (i = 0 ; i

    It works! :)

  3. Prof says:

    And stupid parser cut my comment:

    for (i = 0 ; i

  4. Prof says:

    OMG! Conspiracy of parses…

    for (i = 0 ; i < 12 ; i++) { } // >

Leave a Reply