首页 新闻 会员 周边 捐助

.NET MVC 升级到5.1后,View视图中代码报错

1
悬赏园豆:30 [已关闭问题] 关闭于 2014-05-24 17:58

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

但View视图中相关的很多代码都报错,比如:

1.@model找不到

2.@Html找不到,本该是System.Web.MVC的HtmlHelper,系统却将其认成是

System.Web.WebPages.HTML.HtmlHelper

等等

 

我觉的是升级时,Web.config出毛病导致的升级不完整,请问如何解决?

问题补充:

我已经在stackoverflow上找到解决方案了:

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.

chutianshu_1981的主页 chutianshu_1981 | 初学一级 | 园豆:43
提问于:2014-05-23 19:30
< >
分享
所有回答(3)
0

Views/Web.Config 配置的问题,新建一个MVC项目把内容复制过来

Y2zz | 园豆:393 (菜鸟二级) | 2014-05-23 23:36

这方法我试过,并不管用

支持(0) 反对(0) chutianshu_1981 | 园豆:43 (初学一级) | 2014-05-24 11:10
0

ASP.NET MVC里面,每个版本都依赖一些组件,而这些组件有些是不对低版本兼容的。你用 .nuget 升级,但是Web.Config里面的配置还是针对4的。而5的配置中有些组件应该都是升级版的。但是Web.config里面并没有修改。问题很可能出在了这一块儿。我之前遇到过类似的情况。希望可能帮到你。

JRoger | 园豆:258 (菜鸟二级) | 2014-05-24 09:49

原理我是知道的,关键是怎么改,我把相应版本号改过了,对应引用中dll的版本号,还是不行

支持(0) 反对(0) chutianshu_1981 | 园豆:43 (初学一级) | 2014-05-24 11:11
0

已解决

chutianshu_1981 | 园豆:43 (初学一级) | 2014-05-24 11:49

 哥们, 我也遇到同样的问题了,. 你是怎么解决的? 

支持(0) 反对(0) Eysa | 园豆:62 (初学一级) | 2015-08-19 11:14
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册