使用nuget将项目中MVC4 升级到MVC5,之后项目还可以正常编译运行,

但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视图中代码报错的更多相关文章

  1. osx升级到10.10后,使用pod install报错解决的方法

    先看下网上的解决方法例如以下: 先依照这个文章做:http://blog.csdn.net/dqjyong/article/details/37958067 大概过程例如以下: Open Xcode ...

  2. osx升级到10.10后,用pod install报错最终解决办法

    转载自:http://blog.csdn.net/liuyujinglove/article/details/40582197 http://blog.csdn.net/dqjyong/article ...

  3. osx升级到10.10后,用pod install报错终于解决的方法

    先依照这个文章做:http://blog.csdn.net/dqjyong/article/details/37958067 大概过程例如以下: Open Xcode 6 Open Preferenc ...

  4. Mysql 升级到 5.6 后插入语句时间字段报错:Incorrect datetime value: '' for column 'createtime'

    今天部署服务器项目运行,当遇见有时间数据对象的插入和更新操作的时候,就报错,如下: Caused by: com.mysql.jdbc.MysqlDataTruncation: Data trunca ...

  5. jenkins 安装 SVN Publisher 后向 svn 提交代码报错: E170001: Authentication required for...

    问题描写叙述 安装并启动 jenkins 后,加入了 SVN Publisher 插件,然后在构建任务的"构建后操作"操作中加入了"Publish to Subversi ...

  6. (转载)jenkins 安装 SVN Publisher 后向 svn 提交代码报错: E170001: Authentication required for...

    问题描写叙述 安装并启动 jenkins 后,加入了 SVN Publisher 插件,然后在构建任务的“构建后操作”操作中加入了“Publish to Subversion repository”相 ...

  7. IE对象最后一个属性后不要加逗号,否则在IE7及以下版本中会报错

    某函数返回一个对象,如果在最后一个属性后加逗号,IE7及以下版本中会报错 正确代码: return{ top:rect.top-top, bottom:rect.bottom-top, left:re ...

  8. MySQL在windows系统中修改datadir路径后无法启动问题,报错1067

    windows server2008下如何更改MySQL数据库的目录的帖子已经很多了,这里简单介绍一个步骤,如果不成功请先查看其它帖子. 更改默认的mysql数据库目录 将 C:\Documents ...

  9. 备库搭建后,进入备库报错psql: FATAL: the database system is starting up

        备库搭建后,进入备库报错psql: FATAL:  the database system is starting up  原因:备库配置文件没有hot_standby = on   mast ...

随机推荐

  1. .Net Core Linux部署之进程守护 Supervisor 安装配置

    1.Supervisor 安装 //安装easy_install yum install python-setuptools //安装Supervisor easy_install superviso ...

  2. VS2012 创建 WebService

    1.文件——新建——项目——Visual C#——Web——ASP.NET 空 Web 应用程序. 2.右键项目——添加——新建项——Web——Web 服务. 3.按 F5 启动调试,浏览器将显示接口 ...

  3. thinkphp3.2.3定时任务 不能获取本模块config, 不能获取本模块的其他配置

    一开始创建就有一个home模块再创建一个Data模块 定时任务在/Application/Common/Conf/crons.php中,这里不讲怎么创建定时任务. Data模块的配置文件路径如下/Ap ...

  4. [洛谷P3811]【模板】乘法逆元

    P3811 [模板]乘法逆元 题意 求1-n所有整数在模p意义下的逆元. 分析 逆元 如果x满足\(ax=1(\%p)\)(其中a p是给定的数)那么称\(x\)是在\(%p\)意义下\(a\)的逆元 ...

  5. C# 获取命名空间对应的程序集位置

    由于同名命名空间会被多个程序集使用,C#没有提供直接的方法(对象浏览器也不行)通过命名空间获得程序集位置,这样就不方便找到那些引用文件时什么. 那么可以在立即窗口,中断某个代码的时候,去查询类所在程序 ...

  6. Pytorch入门笔记

    import torch.nn as nn import torch.nn.functional as F class Net(nn.Module): def __init__(self): #nn. ...

  7. JS判断键盘上的上下左右键

    document.onkeydown=function(event){ var e = event || window.event || arguments.callee.caller.argumen ...

  8. 简单粗暴地理解js原型链–js面向对象编程

    简单粗暴地理解js原型链–js面向对象编程 作者:茄果 链接:http://www.cnblogs.com/qieguo/archive/2016/05/03/5451626.html 原型链理解起来 ...

  9. sql杂记

    Create procedure 存储过程的声明 PIVOT的一般语法是:PIVOT(聚合函数(列) FOR 列 in (…) )AS P 通俗简单的说:PIVOT就是行转列,UNPIVOT就是列传行 ...

  10. LeetCode OJ:Rotate List(旋转链表)

    Given a list, rotate the list to the right by k places, where k is non-negative. For example:Given 1 ...