为什么我的剃须刀观点抱怨"}预期"升级后的剃刀2 / MVC 4? [英] Why is my razor view complaining "} expected" after upgrade to razor 2 / mvc 4?
问题描述
我有一个现有的剃须刀1 / MVC 3观点,与一些嵌套如果
- 很简单,但升级到剃刀2 / MVC 4后抱怨在运行时编译( BuildViews
)关于}预期
。它用于正常工作。
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.
- 在我已经检查的所有元素都能很好地形成/关闭
- 在我已经检查了所有的
{
/}
平衡 - 这是未结束的-file问题
- 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
什么是错的?
推荐答案
若干遗留剃须刀怪事被固定在剃刀2 / MVC 4的升级; 1有趣小问题,就是在剃刀1,下面是合法的(在一个code区):
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;
注意 @
有多余的和不正确的,但剃须刀1不抱怨。但是,剃须刀2更挑剔和迷糊,报告}预期
错误。此行应改为:
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.
这篇关于为什么我的剃须刀观点抱怨"}预期"升级后的剃刀2 / MVC 4?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!