ViewBag.Title错误

jus*_*eve 23 asp.net-mvc-3

使用当前RC2 - 生成的模板Razor视图包括:

@{
    ViewBag.Title = "Details1";
    Layout = "/Views/Shared/_Public.cshtml";

}
Run Code Online (Sandbox Code Playgroud)

在ViewBag.Title下有一个红色波浪形和这个编译错误:'

Error   4   One or more types required to compile a dynamic expression cannot be found. Are you missing references to Microsoft.CSharp.dll and System.Core.dll? c:\Visual Studio 2010\Projects\myProj\Views\Webinar\Details1.cshtml 6   2   TTSTrain.Webinars.WebEntry
Run Code Online (Sandbox Code Playgroud)

但该项目正确构建和运行.错误是否表明应该解决的其他问题?

Pet*_*ter 16

targetFramework<compilation>Web.config文件中的元素中删除属性后,我遇到了同样的问题.

一旦我恢复它

<compilation debug="true" targetFramework="4.0">
Run Code Online (Sandbox Code Playgroud)

一切都恢复正常!

  • 我有问题并检查,我已经有那行<compilation debug ="true"targetFramework ="4.0"> :( (4认同)

kef*_*er9 9

我用以下方式解决了它:

首先我注意到使用gacutil(全局程序集缓存实用程序),它包含两个对System.Core的引用,一个引用到4.0版,一个引用到3.5版.显然在剃刀视图中,即使在项目中我有正确的4.0版本引用,它仍然使用版本3.5,这就是为什么我得到关于动态类型的错误.要检查您的案例是否以管理员身份打开Visual Studio命令提示符并执行:

gacutil -l System.Core
Run Code Online (Sandbox Code Playgroud)

要删除对旧版System.Core的引用,我执行了以下步骤:

- cd %systemroot%\assembly\
Run Code Online (Sandbox Code Playgroud)

从这里你可能有一个"gac"目录,所以你必须在每个目录中搜索才能找到你的组件.对我来说,它位于"gac_MSIL"目录中.

- 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
Run Code Online (Sandbox Code Playgroud)

之后我在visual studio中再次打开我的解决方案并且错误消失了,它正确地引用了System.Core 4.0并且我没有得到动态错误:)

我希望它也能帮助你,Best,N.


mar*_*ind 1

你有关于Microsoft.CSharp和 的参考吗System.Core

MVC 视图(通常)在您访问站点时动态编译,而不是在 VS 中编译应用程序时动态编译。我想您在运行该网站时会遇到问题。只需添加两个参考文献就可以了。