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

Cannot serialize JPA bean due to presence of proxies

hibernate jpa jersey jax-rs

I am trying to expose an object as XML using JAX-RS.

Why is blur.js trying to access the file “none”?

javascript jquery html transparency

I'm trying to use blur.js to create a blur effect on my site so you can see the site background behind the content. However, it appears to be trying to access an image called "none."

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.