发行迁移MVC3应用MVC4:编译器错误消息:CS1513:}预期 [英] Issue migrating MVC3 Application to MVC4: Compiler Error Message: CS1513: } expected

查看:572
本文介绍了发行迁移MVC3应用MVC4:编译器错误消息:CS1513:}预期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个非常奇怪的错误,我想这可能是一个剃须刀错误。我使用VS 2012年,MVC4,框架4.5。

This is a really weird error, I think it may be a razor bug. I'm using VS 2012, MVC4, Framework 4.5.

按照这些指示:<一href=\"http://www.asp.net/whitepapers/mvc4-release-notes#_Toc303253806\">http://www.asp.net/whitepapers/mvc4-release-notes#_Toc303253806
我从MVC3项目中创建一个新的MVC4项目,然后我复制我所有的code(控制器,视图的ViewModels)吧。

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工作得很好,直到我测试了一个View里面有一个自定义的助手和里面它有一个的foreach ,一是开关,三如果语句,然后我把其他一些定制的助手在那里了。

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.

这是在两个项目完全相同code,在MVC3它的工作原理,但在MVC4它显示了这个消息:

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.

我GOOGLE了这个问题,但我只是发现,没有回答这个问题:
<一href=\"http://www.1771.in/asp-net-mvc-4-issues-migrating-mvc3-view-in-vs-2012-rc.html\">http://www.1771.in/asp-net-mvc-4-issues-migrating-mvc3-view-in-vs-2012-rc.html

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?

推荐答案

MVC4的剃刀解析器是MVC3不同。
剃刀v3中具有高级解析器的特性和另一方面严格解析比较MVC3

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.

在转换到MVC3如果MVC4你没有在正确的方式使用剃刀语法,可能会遇到语法错误在视图中。

You may run into syntax error in view while converting MVC3 to MVC4 if you have not used razor syntaxes in correct manner.

一些常见的剃刀code错误未在剃刀不允许V2是解决方法:

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.

Don’t : @{if(check){body}}
Recommended : @if(check){body}

- >避免在你已经在服务器范围内使用@

--> Avoid using @ when you are already in server scope.

Don’t : @if(@variable)
Recommended : @if(variable)

Don't : @{int a = @Model.Property }
Recommended : @{int a = Model.Property }

这篇关于发行迁移MVC3应用MVC4:编译器错误消息:CS1513:}预期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆