Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

C# ASP.NET MVC Basics Views Adding Design Files

Xiaolong Yang
Xiaolong Yang
4,374 Points

The name viewbag does not exist in the current context

When I was trying to copy and past the files into my project, as what the video said, the VS told me that something can't be copied (because of something about permission? can't recall...) I thought that might because some files were running, so I closed the VS and restarted it after the copy is finished. But then I found for some reason, both the Detail.cshtml and web.config are missing, and since I forgot to push the code, I couldn't get them back from github. I got back to the nearest version I could find, and redo the class step by step, but for some reason, when I move the properties to .cs file, and add ViewBag to cshtml, VS add a red line under every ViewBag, saying "The name viewbag does not exist in the current context". I have googled this problem, some said it's because the web.config is missing, but when I checked it, I found it's definitely there, not missing. Is there something I could do to solve the problem?

I have this same problem, is there any solid fix for this?

1 Answer

That sounds like a big mess. Just to be sure, it's referring to the web.config that's located in the views folder and not the one in the root folder. You might have to create a new project and copy the controllers, views, and models to the new project to fix the corruption.