Error: The name 'ViewBag' does not exist in the current context

7

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

I searched for various solutions online but still have not found anything to solve. I would not want to have to upgrade to MVC 5 because I have many projects in parallel and would have to upgrade all.

Is there a solution to this problem that I think is compatibility?

    
asked by anonymous 18.11.2015 / 13:07

2 answers

6

There is an update for Visual Studio 2015 which re-enables MVC4 syntax .

Still, I see no advantage in maintaining a project in MVC4. -and-web-api-2 "> Here is a migration guide for MVC5 that I have used a few times in my projects.

    
18.11.2015 / 14:50
4

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

devenv /ResetUserData

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

18.11.2015 / 13:33