Error: The name 'Viewbag' does not exist in the Current context

Asked

Viewed 1,872 times

7

Good morning, I have projects using System.Web.MVC na versão 4.0.0.1, worked normally in the 2013 version of Visual Studio, now I’m trying to work with Visual Studio 2015 and my Views no longer recognize some properties for example ViewBag e @model, they continue to work but are highlighted in red with the following message "The name 'Viewbag' does not exist in the Current context".

I’ve been looking at a number of online solutions, but I haven’t found anything to fix it yet. I would not like to have to upgrade to MVC 5 because I have many projects in parallel and would have to update all.

Is there any solution to this problem that I believe is compatibility ?

  • I don’t have time to create an answer, take a look here

  • Right-click yours in your view (e.g., Index.cshtml) and go to "Open With", and check that the "Razor Editor" option is Default.

2 answers

6


  • 1

    Thank you Gypsy, it worked correctly the update. I don’t see the advantage either but I’m running out of time to migrate the projects to MVC 5 as soon as possible. Thank you!

4

I have been through this a few times and it seems that the problem is related to HTML Editor when it tries to interpret code in Razor, I was able to solve this problem some by closing all the tabs that were open and reopening the one where the problem occurred. If this does not solve the problem I have seen some people recommending restarting user settings starting Visual Studio with the command line argument /ResetUserData.

devenv /ResetUserData

In Stack Overflow in English, there are some questions about the same problem in Visual Studio 2015 and have been solved in this way as well:

Browser other questions tagged

You are not signed in. Login or sign up in order to post.