Issue migrating MVC3 Application to MVC4: Compiler

2019-02-08 15:55发布

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

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 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.

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.

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?

7条回答
冷血范
2楼-- · 2019-02-08 16:54

Try to add this line in web.config

<compilation debug="true" batch="false">

Now, when getting the error you should be able to open the temporary generated .cs file and take a look at generated code.

Maybe then you will more easily spot the problem.

For details look here Debugging ASP.NET generated code

查看更多
登录 后发表回答