Why is my razor view complaining "} expected" after upgrade to razor 2 / mvc 4?

I have an existing razor 1 / mvc 3 view, with a few nested if - very simple, but after upgrading to razor 2 / mvc 4 it is complaining at runtime and compile (BuildViews) about } expected. It used to work fine.

  • I've checked all the elements are well-formed / closed
  • I've checked that all the { / } are balanced - this isn't the end-of-file issue

What can be wrong?

Answers


A number of legacy razor oddities were fixed in the razor 2 / mvc 4 upgrade; one interesting gotcha is that in razor 1, the following is legal (in a code region):

string foo = @Some.Complex.Expression;

Note that the @ there is superfluous and incorrect, but that razor 1 does not complain. However, razor 2 is more fussy and gets confused, reporting the } expected error. This line should be replaced with:

string foo = Some.Complex.Expression;

This is a bit subtle, because the error that occurs has nothing to do with braces ({/}), and can be some lines away from the reported line.


Need Your Help

C++ Compiler Error C2280 "attempting to reference a deleted function" in Visual Studio 2013 and 2015

c++ visual-c++ copy-constructor c++14

This snippet is compiled without errors in Visual Studio 2013 (Version 12.0.31101.00 Update 4)

IPC performance: Named Pipe vs Socket

linux performance sockets ipc named-pipes

Everyone seems to say named pipes are faster than sockets IPC. How much faster are they? I would prefer to use sockets because they can do two-way communication and are very flexible but will choose