zoukankan      html  css  js  c++  java
  • NET MVC 升级到5.1后,View视图中代码报错

    使用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

  • 相关阅读:
    好用的镜头站下载工具
    300+Jquery, CSS, MooTools 和 JS的导航菜单资源
    股票入门2
    MEF学习笔记(6):出口和元数据
    MEF学习笔记(5):迟延加载导出部件
    WinForm控件复杂数据绑定常用数据源(如:Dictionary)(对Combobox,DataGridView等控件DataSource赋值的多种方法)
    wpf 多线程绑定控件
    HTTP 错误 404.2 Not Found 由于 Web 服务器上的“ISAPI 和 CGI 限制”列表设置,无法提供您请求的页面
    ADODB.Stream 错误 '800a0bbc' 写入文件失败。
    'System.Windows.StaticResourceExtension' threw an exception
  • 原文地址:https://www.cnblogs.com/wudiliujie/p/4350843.html
Copyright © 2011-2022 走看看