Visual Studio 2019升级MVC5提示The name 'ViewBag' does not exist in the current context错误信息的解决办吧

原来的项目是MVC4的,我就升级到MVC5但是可以编译,就是会提示ViewBag的错误信息如下图

Visual Studio 2019升级MVC5提示The name 'ViewBag' does not exist in the current context错误信息的解决办吧

在网上查找了一下,觉得应该是升级引起的,那么修改Web.config就应该没有问题了

首先是项目目录下的web.config中的版本号红色箭头处

Visual Studio 2019升级MVC5提示The name 'ViewBag' does not exist in the current context错误信息的解决办吧

下图中的版本是4.0.0.0 把这里修改为5.2.7.0 然后重新打开项目就ok了 

Visual Studio 2019升级MVC5提示The name 'ViewBag' does not exist in the current context错误信息的解决办吧 下图是正常后的效果

Visual Studio 2019升级MVC5提示The name 'ViewBag' does not exist in the current context错误信息的解决办吧