Viewbag.Title 错误:找不到编译动态表达式所需的一种或多种类型。您是否缺少参考资料?

2024-01-19

我有一个 ASP.NET MVC 5 Web 应用程序。在每个 .cshtml 视图文件中,我收到以下错误Viewbag: 找不到编译动态表达式所需的一种或多种类型。您是否缺少参考资料?

我引用了 Microsoft.CSharp.dll 和 System.Core.dll。

这是我的根 web.config 文件:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
  </configSections>
  <connectionStrings>
    <add name="DefaultConnection" connectionString="***" providerName="System.Data.SqlClient" />
  </connectionStrings>
  <appSettings>
    <add key="webpages:Version" value="3.0.0.0" />
    <add key="webpages:Enabled" value="false" />
    <add key="ClientValidationEnabled" value="true" />
    <add key="UnobtrusiveJavaScriptEnabled" value="true" />
    <add key="RouteDebugger:Disabled" value="true" />
  </appSettings>
  <system.web>
    <authentication mode="None" />
    <compilation debug="true" targetFramework="4.5" />
    <httpRuntime targetFramework="4.5" />
    <globalization culture="ro-RO" uiCulture="ro" />
  </system.web>
  <system.webServer>
    <modules>
      <remove name="FormsAuthenticationModule" />
    </modules>
  </system.webServer>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="0.0.0.0-1.6.5135.21930" newVersion="1.6.5135.21930" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Antlr3.Runtime" publicKeyToken="eb42632606e9261f" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-3.5.0.2" newVersion="3.5.0.2" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.Owin" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-2.1.0.0" newVersion="2.1.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.Owin.Security" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-2.1.0.0" newVersion="2.1.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.Owin.Security.OAuth" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-2.1.0.0" newVersion="2.1.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.Owin.Security.Cookies" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-2.1.0.0" newVersion="2.1.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.AspNet.Identity.Core" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.AspNet.Identity.EntityFramework" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Autofac" publicKeyToken="17863af14b0044da" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-3.3.0.0" newVersion="3.3.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-5.1.0.0" newVersion="5.1.0.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
    <providers>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
    </providers>
  </entityFramework>
</configuration>

这是 Views 文件夹中的 web.config:

<?xml version="1.0"?>

<configuration>
    <configSections>
        <sectionGroup name="system.web.webPages.razor" type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
            <section name="host" type="System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
            <section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
        </sectionGroup>
    </configSections>

    <system.web.webPages.razor>
        <host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=5.1.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
        <pages pageBaseType="System.Web.Mvc.WebViewPage">
            <namespaces>
                <add namespace="System.Web.Mvc" />
                <add namespace="System.Web.Mvc.Ajax" />
                <add namespace="System.Web.Mvc.Html" />
                <add namespace="System.Web.Optimization"/>
                <add namespace="System.Web.Routing" />
            </namespaces>
        </pages>
    </system.web.webPages.razor>

    <appSettings>
        <add key="webpages:Enabled" value="false" />
    </appSettings>

    <system.webServer>
        <handlers>
            <remove name="BlockViewHandler"/>
            <add name="BlockViewHandler" path="*" verb="*" preCondition="integratedMode" type="System.Web.HttpNotFoundHandler" />
        </handlers>
    </system.webServer>
</configuration>

我可以构建解决方案,并且 Web 应用程序按预期工作,但我不断在 IDE 中收到此错误,这非常烦人。我花了一整天的时间试图解决这个问题。有人可以告诉我如何修复它吗?

Edit:

当一切正常时,当我导航到 ViewBag 的定义 (F12) 时,我得到Assembly System.Web.Mvc.dll, v5.1.0.0 from Recipes.Web\Bin\System.Web.Mvc.dll有 4 个 using 语句,其中之一是System.Runtime.CompilerServices.

当出现错误时,当我导航到 ViewBag 的定义 (F12) 时,我得到相同的结果Assembly System.Web.Mvc.dll, v5.1.0.0 from Recipes.Web\Bin\System.Web.Mvc.dll,但是只有 3 个 using 语句,System.Runtime.CompilerServices离开了。

有时,错误不会出现,但如果我关闭解决方案和 Visual Studio,然后重新打开解决方案,错误会再次出现。我什至不重建或做任何其他事情。

为什么会发生这种情况?


我以管理员身份运行 VS 2012 时没有这个问题。

否则,对我有用的是:

  1. 在根 Web 配置中添加了建议的参考,以将正确的程序集作为编译节点的子节点<system.web> <compilation debug="true" targetFramework="4.5"> <assemblies> <add assembly="System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" /> </assemblies></compilation> </system.web>

  2. 设置副本local = true属性为System.Core and Microsoft.CSharp

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Viewbag.Title 错误:找不到编译动态表达式所需的一种或多种类型。您是否缺少参考资料? 的相关文章

  • 如何在ListBox中加载大量数据? ASP.NET MVC 应用程序

    我正在使用 ASP NET MVC 应用程序 要求用户能够从可能包含超过 30 000 个条目的列表框中选择一个项目 是否有一种使用 Ajax 调用来填充此 ListBox 内容的动态方法 效果良好 我是否最好只填充服务器上的 ListBo
  • mvc 2中的图像上传和预览

    我正在通过转换 asp net 网站来学习 mvc 2 在我的页面中 我必须上传图像并显示图像的预览 下面给出了我的 asp net 页面的屏幕截图 我将模型创建为 public class Contest public int conte
  • ASP.net MVC 项目无法在 IIS 上编译

    我以前只是将 ASP NET 网站上传到实时服务器 IIS 会自动编译它们 但是 当我对 asp net MVC 项目执行相同操作时 我只是收到错误 并且我需要在上传项目之前发布 构建 项目 注意1 我使用的是VWD 2008 Expres
  • asp.net mvc 它能处理所有请求吗? - iis 7集成模式

    我有一个使用 asp net mvc 构建的网站 在 IIS 7 上使用集成模式运行 我注意到 当我输入 mysite com test html 时 我得到了 The IControllerFactory did not return a
  • 如何为客户端和服务器缓存设置不同的缓存过期时间

    我想让某些页面为客户端提供 10 分钟缓存 为服务器提供 24 小时缓存 原因是如果页面发生变化 客户端将在 10 分钟内获取更新版本 但如果没有任何变化 服务器只需每天重建一次页面 问题在于输出缓存设置似乎覆盖了客户端设置 这是我的设置
  • AutoMapper.Mapper 不包含 CreateMap 的定义

    这可能是一个基本问题 但想知道我没有得到 AutoMapper Mapper CreateMap 方法 我使用了错误的 AutoMapper 参考 包吗 谢谢 静态版本CreateMap方法在 4 2 中已弃用 然后在版本 5 0 中从 A
  • asp.net mvc 4 - 可以在每个线程共享 DbContext 吗?

    From 每个 Web 请求一个 DbContext 为什么 https stackoverflow com questions 10585478 one dbcontext per web request why 我的理解是 DbCont
  • 将多个对象传递给我的控制器

    我将一个对象传递给我的控制器 如下所示 var form JSON stringify subRevisedRequest frmRevised val subSubcontractor frmSubcontractor val subDe
  • 阻止未确认电子邮件的用户使用 Identity 2 登录 ASP.Net MVC

    在 Microsoft Identity 2 中 用户可以确认我从以下位置下载了 Identity 2 示例项目的电子邮件地址here https www nuget org packages Microsoft AspNet Identi
  • 使用 AJAX 加载部分视图不起作用

    请原谅我 我是 MVC 和 AJAX 的新手 目前我只是提交一个表单 我想使用表单中的数据使用 ajax 更新部分视图中的表 My UserInfo部分视图如下所示 model IEnumerable
  • 如何强制 Visual Studio 2008 生成 Designer.cs,例如不管怎样.aspx.designer.cs

    我在使用 Visual Studio 2005 使用网站技术生成的 Asp Net V2 0 中有一些 Web 表单 想要将它们导入到设置为 v3 5 Asp Net MVC 的 Visual Studio 2008 我在其中使用项目技术
  • ASP.NET MVC,控制器可以改变提交的值吗?

    ASP NET MVC 中是否允许更改提交的值 HttpPost public ActionResult Create Person toCreate toCreate Lastname toCreate Lastname A return
  • 如何终止会话或会话 ID (ASP.NET/C#)

    当用户单击注销按钮时 如何销毁会话 会话 名称 我正在 MSDN 上查看 ASP NET API Reference 它似乎没有太多信息 看来还是比较有限的 但我找不到 ASP NET 类等的任何其他页面 我努力了 Session Aban
  • 缺少添加控制器/视图的上下文菜单

    我已将 ASP NET MVC 4 集成到现有的 asp net 网站中 两者都工作正常 但我没有看到任何菜单 快捷方式来在 Visual Studio IDE 中创建控制器 视图 这些仅适用于 ASP NET MVC 模板吗 这些仅适用于
  • 将 EditForm 绑定到数组时如何让 EditContext.Validate() 工作

    我创建了一个EditForm像这样包装表格 Index razor using System ComponentModel DataAnnotations
  • 从另一台设备访问 Azure 模拟器

    我有两个不同的项目 Windows Phone 8 应用程序 我正在真实的物理开发设备上运行 Azure 云服务 其中包含一个简单的 WebRole 端点 其中包含 ASP NET MVC WebAPI 我的目标很简单 使用从真实设备运行的
  • 有没有办法让 DefaultModelBinder 在绑定到 List 时忽略空项

    我有一个场景 我想更改 DefaultModelBinder 绑定到枚举列表的方式的行为 我有一个枚举 public enum MyEnum FirstVal SecondVal ThirdVal 和一个模型类 public class M
  • 在asp net mvc中简单的图像上传

    我正在构建一个简单的学校门户 我一直坚持将图像上传到我的应用程序中 即用户应该将学校图像上传到我的服务器 我的图像目录为 Content Images 所有上传图像都应该上传到这个目录 我有以下代码 input type file id S
  • orchard cms路由问题

    我创建了一些自定义内容类型 其中包括路线部分 以便我的内容管理员可以编辑项目的别名 我没有运气配置一条路线 使我自己的控制器能够为这些项目的请求提供服务 核心 Routable 模块中到 ItemController 的路径的路由优先级为
  • asp.net mvc 主要细节

    我想使用 ASP NET MVC Entity Framework 创建一个用于订单输入的网页 此页面包含订单和订单输入信息 对于每个订单 我可以有多个订单详细信息 如果您知道如何使用 ASP NET MVC Entity Framewor

随机推荐

  • 如何修复获取 URL 时出现的 HTTP 错误。爬行时java中的Status = 500?

    我试图从评论页面抓取用户对 imdb 电影的评分 我的数据库中的电影数量约为 600 000 我使用jsoup来解析页面 如下所示 抱歉 我没有在这里写完整的代码 因为它太长了 try connecting to mysql db Resu
  • Firefox 不会恢复服务器发送的事件连接

    使用Python和CherryPy实现的测试用例 import cherrypy time class Root cherrypy expose def index self return r
  • Ajax 和防止双重“提交”

    我正在处理一个遗留应用程序 他们使用 a 标签来进行许多 Ajax 表单 提交 如果我们使用 input 按钮 我们只需设置 input 标签的禁用属性即可 但在超链接上禁用不是规范的一部分 并且跨浏览器不一致 我们正在寻找一种简单的解决方
  • 在 ViewPager 中实现弹性/弹跳动画效果的最佳方法是什么? [复制]

    这个问题在这里已经有答案了 我想显示一个ViewPager https developer android com reference android support v4 view ViewPager html具有弹跳 弹性滑动效果 我认
  • 谁最初发明了这种类型的语法:-*-编码:utf-8-*-[重复]

    这个问题在这里已经有答案了 Python 将以下内容识别为定义文件编码的指令 coding utf 8 我以前肯定见过这种说明 var value 所以我假设 Python 没有发明它们 也不是唯一使用此类指令的语言 这个语法从何而来 是否
  • 自定义 UITextField 清除按钮

    是否可以自定义清除按钮的图像UITextField 我有一个深色的文本字段背景 x 不够明显 您可以将自己的自定义清除按钮设置为文本字段的rightView财产 确保设置rightViewMode财产给UITextFieldViewMode
  • 使用 Angular 切换列表中的类

    我想在使用 AngularJS 单击元素时切换类 我需要单击的元素来接收类 并需要列表中的任何其他项目来释放类 我已经为此研究了一些假设的解决方案 但是在实施它们时 它们不能正常工作 我不明白为什么它们会这样 建议的一般解决方案是将变量设置
  • C++ 中的不透明值是什么?

    C 中的 不透明值 是什么 不透明 在英语中的定义是 不能被看穿 不透明 在计算机科学中 这意味着除了值本身的类型之外不显示任何细节的值 人们经常使用C型FILE作为经典的例子 但通常这是not不透明 细节显示在stdio h任何人都可以看
  • 如何使用 CIColorControls 通过 UISlider 和 Swift 更改亮度、对比度和饱和度

    我正在开发一个照片滤镜应用程序 正如你所看到的 我添加了一个功能来调整对比度 亮度 饱和度和噪音 但问题是它们是独立工作的 这意味着当我开始编辑对比度时调整亮度时 它会返回到原始亮度 这是当我将亮度设置为最大 图像变白 然后尝试调整其对比度
  • 使用 Jquery,将表中的一行替换为新行

    假设我有一张桌子 table tr class old row td 1 td td 2 td td class edit Edit td tr tr class old row td 1 td td 2 td td class edit
  • 在多个音乐文件上运行命令行

    我正在使用一个名为 metaflac 的 CLI 程序 http flac sourceforge net documentation tools metaflac html http flac sourceforge net docume
  • 适用于 Android 的 Google 地图我的位置自定义按钮

    如何更改谷歌地图我的位置默认按钮 我设置了位置启用并在地图上绘制标准图像来查找位置 是否可以更改默认图像 请参阅下面的自定义按钮 xml 文件
  • dart 中的逆映射

    假设我在 dart 中有以下地图 Map f 0 0 1 1 2 0 3 1 4 0 5 1 dart中有没有什么东西可以让你轻松使用地图的逆图f 例如 逆映射f 0 用数学符号表示 应该等于集合0 2 4在这种情况下 如果值是唯一的 那么
  • 如何在ios7中以编程方式将地图颜色从白天更改为晚上

    我正在开发一个适用于 iOS 7 的应用程序 并尝试将地图从白天更改为夜间模式 将夜间模式更改为白天模式 我在 iOS 7 文档中没有找到任何相关的 API 来执行此操作 这不是内置功能MKMapKit所以你所要求的如果不自己做是不可能的
  • Jupyter Notebook 不允许我在多行中输入 MySQL 查询

    如上所述 我无法在 Jupyter 中多行输入查询 这很烦人 因为编写和读取我自己的查询比较困难 有没有办法切换多行和单行输入 我已经用谷歌搜索了好几次 但文档似乎没有多大帮助 PS 找到了输入 sql 而不是 sql 的愚蠢解决方案 使用
  • 如何在 GLSL / WebGL 中将 1 个 32 位整数打包为 4 个 8 位整数?

    我正在寻求并行化一些复杂的数学 而 WebGL 看起来是实现这一目标的完美方法 问题是 您只能从纹理中读取 8 位整数 理想情况下 我希望从纹理中获取 32 位数字 我的想法是使用 4 个颜色通道来获得每像素 32 位 而不是 4 乘以 8
  • 为什么 DateDiff 返回日期而不是分钟数?

    我需要找出两个字符串之间存在多少分钟 h1 TimeValue 06 00 00 h2 TimeValue 22 00 00 res DateDiff n h1 h2 然而 res 17 08 1902 而预期结果是 960 Sub cal
  • 让 AdView 实际显示

    我的 google adview 有问题 它没有显示 我挖了一段时间 发现人们对填充有问题 所以我去掉了填充 但仍然没有运气 这是我的相关清单数据
  • 如何将div内的img向右对齐?

    我想知道如何将div内的图像对齐到右侧 可以给周边div a text align right 这将在图像左侧留下空白区域 图像将占据整行 如果您希望内容显示在图像的左侧 请使用 float right 在图像上 然而 周边div然后将需要
  • Viewbag.Title 错误:找不到编译动态表达式所需的一种或多种类型。您是否缺少参考资料?

    我有一个 ASP NET MVC 5 Web 应用程序 在每个 cshtml 视图文件中 我收到以下错误Viewbag 找不到编译动态表达式所需的一种或多种类型 您是否缺少参考资料 我引用了 Microsoft CSharp dll 和 S