'ViewBag'不存在于当前上下文存在的名称 - 的Visual Studio 2015年 [英] The name 'ViewBag' does not exist in the current context - Visual Studio 2015

查看:3503
本文介绍了'ViewBag'不存在于当前上下文存在的名称 - 的Visual Studio 2015年的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开始在ASP.NET开发一次,我跑在Visual Studio中的一个小错误。我的.cshtml文件使用一些功能剃须刀时显示错误。例如'ViewBag'这个名字并不在目前的情况下存在。这里有一个画面: http://puu.sh/gT6yg/4b44319fa7.png

I'm starting to develop in ASP.NET again and I ran into a small error within Visual Studio. My .cshtml files show errors when using a few razor functions. For example "The name 'ViewBag' does not exist in the current context". Here is a picture: http://puu.sh/gT6yg/4b44319fa7.png

我使用的是示范项目。你可以在这里找到项目: https://github.com/Wintellect/角MVC-食谱/树/主/ BasicProject

I am using a demo project. You can find the project here: https://github.com/Wintellect/Angular-MVC-Cookbook/tree/master/BasicProject

我已经通过其他几个线程看去,最建议更新web.config文件(S)。这两个配置文件都已经present并且由于它是一个pretty流行的演示中,我认为它有它所有必要的配置。我当然通过这些配置文件看,它们确实也包括了建议的解决方案。

I have looked through several other threads and most suggest to update the web.config file(s). These 2 config files are already present and since it's a pretty popular demo I assume it has all the required configuration in it. I have of course looked through these config files and they do indeed include the suggested solutions.

其他详情:


  • 我已经使用清洁&放大器;重建的解决方案,但什么也没有改变。

  • 当我创建一个完全新的MVC项目它的工作

  • 我的朋友有相同的问题

  • 我们都使用VS 2015年和Windows 10

  • 我仍然可以运行应用程序,它的工作。

先谢谢了。

推荐答案

我有这个问题,尽管拥有所有正确的配置。

I had this issue despite having all the correct configuration.

这竟然是一些<一个href=\"https://www.stevefenton.co.uk/2015/11/how-to-fix-broken-intellisense-in-visual-studio-razor-views/\">bad在组件缓存文件,$ P $无法识别ViewBag,型号pventing剃刀意见,HtmlHelpers 。删除这些文件,解决了这个问题(这些文件的良好版本中创建我打开Visual Studio的下一次)。

It turned out to be some bad files in the Component Cache, preventing the Razor views from recognising ViewBag, Model, and HtmlHelpers. Deleting these files solved the problem (good versions of these files were created next time I opened Visual Studio).

该文件位于此处:

C:\Users\your.name.here\AppData\Local\Microsoft\VisualStudio\14.0\ComponentModelCache

我后来看到其他几个开发商机同样的问题,此修复程序迅速解决它。

I have subsequently seen the same issue on several other developer machines and this fix quickly solves it.

这篇关于'ViewBag'不存在于当前上下文存在的名称 - 的Visual Studio 2015年的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆