NET MVC 升级到5.1后,View视图中代码报错
但View视图中相关的很多代码都报错,比如:
1.@model找不到
2.@Html找不到,本该是System.Web.MVC的HtmlHelper,系统却将其认成是
System.Web.WebPages.HTML.HtmlHelper
参考地址 http://stackoverflow.com/questions/4605263/viewbag-title-error
解决方法及原因:System.Core冲突,直接将3.5版本的System.Core删掉,只保留4.0的即可
I solved it in the following way:
First i noticed using gacutil (Global Assembly Cache Utility) that it contained two references to System.Core, one to version 4.0 and one to version 3.5. Apparently inside the razor views, even if in the project i had the correct reference to version 4.0, it was still using version 3.5 and that's why i was getting the error about the dynamic types. To check if that's your case open as administrator Visual Studio Command Prompt and execute:
gacutil -l System.Core
To remove the reference to the old version of System.Core i did the following steps:
- cd %systemroot%\assembly\
From here you may have more that one "gac" directory, so you will have to search within each to find your component. For me, it was within the "gac_MSIL" directory.
- cd gac_msil
- cd System.Core - cd <assembly version number>__<public key token> - erase *.* Say "y" to are you sure. - cd .. - rd <assembly version number>__<public key token> - cd .. - rd System.Core
After that I opened my solution again in visual studio and the error was gone, it references properly to System.Core 4.0 and I was not getting the dynamic errors anymore :)
I hope it will help you as well, Best, N.
我运行的时候,提示我没有权限删除,然后在web.config里面添加
<compilation debug="true" targetFramework="4.0">
<assemblies>
<add assembly="System.Web.Abstractions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.Helpers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.Routing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.WebPages, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
</assemblies>
</compilation>
就可以解决,写上以此备忘。
还有救是System.Web.Mvc 这个文件复制到本地

ViewBag 出现 找不到编译动态表达式所需的一种或多种类型。是否缺少引用?
需要引用 Microsoft.CSharp
NET MVC 升级到5.1后,View视图中代码报错的更多相关文章
- osx升级到10.10后,使用pod install报错解决的方法
先看下网上的解决方法例如以下: 先依照这个文章做:http://blog.csdn.net/dqjyong/article/details/37958067 大概过程例如以下: Open Xcode ...
- osx升级到10.10后,用pod install报错最终解决办法
转载自:http://blog.csdn.net/liuyujinglove/article/details/40582197 http://blog.csdn.net/dqjyong/article ...
- osx升级到10.10后,用pod install报错终于解决的方法
先依照这个文章做:http://blog.csdn.net/dqjyong/article/details/37958067 大概过程例如以下: Open Xcode 6 Open Preferenc ...
- Mysql 升级到 5.6 后插入语句时间字段报错:Incorrect datetime value: '' for column 'createtime'
今天部署服务器项目运行,当遇见有时间数据对象的插入和更新操作的时候,就报错,如下: Caused by: com.mysql.jdbc.MysqlDataTruncation: Data trunca ...
- jenkins 安装 SVN Publisher 后向 svn 提交代码报错: E170001: Authentication required for...
问题描写叙述 安装并启动 jenkins 后,加入了 SVN Publisher 插件,然后在构建任务的"构建后操作"操作中加入了"Publish to Subversi ...
- (转载)jenkins 安装 SVN Publisher 后向 svn 提交代码报错: E170001: Authentication required for...
问题描写叙述 安装并启动 jenkins 后,加入了 SVN Publisher 插件,然后在构建任务的“构建后操作”操作中加入了“Publish to Subversion repository”相 ...
- IE对象最后一个属性后不要加逗号,否则在IE7及以下版本中会报错
某函数返回一个对象,如果在最后一个属性后加逗号,IE7及以下版本中会报错 正确代码: return{ top:rect.top-top, bottom:rect.bottom-top, left:re ...
- MySQL在windows系统中修改datadir路径后无法启动问题,报错1067
windows server2008下如何更改MySQL数据库的目录的帖子已经很多了,这里简单介绍一个步骤,如果不成功请先查看其它帖子. 更改默认的mysql数据库目录 将 C:\Documents ...
- 备库搭建后,进入备库报错psql: FATAL: the database system is starting up
备库搭建后,进入备库报错psql: FATAL: the database system is starting up 原因:备库配置文件没有hot_standby = on mast ...
随机推荐
- LeetCode——remove-duplicates-from-sorted-list-ii
Question Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only dist ...
- C# 删除文件以及文件夹
代码如下: /// <summary> /// 删除文件夹以及文件 /// </summary> /// <param name="directoryPath& ...
- jQuery回车键快速切换下一个input文本框解决方案
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- 缓存技术内部交流_03_Cache Aside
参考资料: http://www.ehcache.org/documentation/3.2/caching-patterns.html http://www.ehcache.org/document ...
- unity3D用什么语言开发好?
unity3D用什么语言开发好? 一.总结 一句话总结:选c# 同时U3D团队也会把支持的重心转移到C#,也就是说文档和示例以及社区支持的重心都在C#,C#的文档会是最完善的,C#的代码实例会是最详细 ...
- Java进阶7并发优化4——JDK并发数据结构
Java进阶7并发优化4——JDK并发数据结构20131114 由于并发程序和串行程序的不同特点,在串行程序中使用的数据结构可能无法在并行程序中直接的正常使用,因为这些数据结构可能不是线程安全的,所以 ...
- C++复习10.对象的初始化拷贝析构函数
对象的初始化.拷贝构造和析构函数 20131002 构造函数.析构函数.赋值函数是类的基本函数.每一个类只有一个析构函数,但是可以有多个构造函数.多个赋值函数.一般如果类中没有显示的声明和定义上述函数 ...
- 1: 介绍Prism5.0(纯汉语版)
Prism帮助更简单的设计丰富,灵活,易维护的WPF桌面程序.其中使用MVVM,组合式视图,事件聚合等设计模式.这很符合一些重要的架构设计及原则.帮助你创建一个模块化的应用程序——可以独立开发松耦 ...
- LeetCode OJ:Implement Stack using Queues(队列实现栈)
Implement the following operations of a stack using queues. push(x) -- Push element x onto stack. po ...
- 【css】CSS3 Media Queries 详解【转】
说起CSS3的新特性,就不得不提到 Media Queries .最近 Max Design 更新的一个泛读列表里,赫然就有关于 Media Queries 的文章.同时位列其中的也有前天我刚刚翻译的 ...