Visual Studio在razor语句中显示语法错误,但是可以工作 [英] Visual studio showing syntax errors in razor statements but works

查看:171
本文介绍了Visual Studio在razor语句中显示语法错误,但是可以工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在MVC 3中有一个项目.它可以完美运行,并且每次构建它都会成功.但是,Visual Studio坚持以每种剃刀语法在视图中显示编译错误.例如:

I've a project in MVC 3. It works perfectly and each time I build it, it succeeds. However, Visual Studio insist in showing compile errors in views in each razor syntax. For example:

名称模型"在当前上下文D中不存在:\ ... Detail.cshtml

The name 'model' does not exist in the current context D:\ ... Detail.cshtml

这行很简单:

@model Namespace.DetailViewModel

我已经尝试过:

  • 清洗液
  • 清洁解决方案并删除binobj文件夹.
  • 关闭VS并重新打开它(即使在中间重新启动).
  • Cleaning solution
  • Cleaning solution and deleting bin and obj folders.
  • Closing VS and reopening it (even with a reboot in the middle).

注意:我正在使用Visual Studio 2012.

Note: I'm using Visual Studio 2012.

推荐答案

我已经解决了!

该项目是在计算机尚未安装MVC 4时创建的.安装后,出于某种原因,它仍然可以正常工作(尽管).

The project was created when the computer didn't have MVC 4 installed yet. After installing it, for some reason, it kept working (despite this).

所以我所做的就是在安装MVC 4之后对MVC 3项目进行了更改:请参阅此处

So what I did was make the changes that should be made in MVC 3 project after installing MVC 4: see here

此后,它进行编译并且错误消失了,但是某些库的版本(System.Web.WebPagesSystem.Web.WebPages.Razor和其他某些库)的版本存在错误.原来是因为他们将Copy Local设置为True.更改之后,一切开始正常运行.

After that, it compiled and the errors disappeared, however there was an error with the versions of some libraries (System.Web.WebPages, System.Web.WebPages.Razor, and some others). That turned out to be because they had Copy Local set to True. After changing that everything started working great.

这篇关于Visual Studio在razor语句中显示语法错误,但是可以工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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