如果是可以运行的,那么大概率是版本有问题,
找了几个有用的文章VS的ASP.NET项目中cshtml突然出错,当前上下文中不存在名称“ViewBag”_当前上下文中不存在viewbag-CSDN博客C#基础 异常之“当前上下文中不存在名称“ViewBag”,当前上下文不存在名称“model”_c#当前上下文中不存在名称怎么解决-CSDN博客
记录一下我自己的问题
<!--<configSections>
--><!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 --><!--
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>-->
发现我的根目录下的web.config是有问题的,把这5.0.0.0版本注销掉就可以了