Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Razor references not resolved in MVC 5 views Visual Studio 2015 Enterprise

My current development environment:

  • Windows 7 Enterprise
  • Visual Studio 2015 Enterprise Update 2
  • Resharper Ultimate 2016.1.2

Project Configuration:

  • C# .Net 4.5
  • MVC 5

I have looked through several threads, blogs for example ViewBag does not exist in the current context - Visual studio 2015

But my *.cshtml page shows few errors relevant to Razor Screen Shot

I have

  • Cleaned the componentModelCache @ C:\Users\your.name.here\AppData\Local\Microsoft\VisualStudio\14.0\ComponentModelCache
  • updated the Views\web.config System.Web.Mvc, Version=5.2.2.0
  • and every possible config update available through the forums & blogs

Still no result. But when I create a brand new project this error does not appear. Any clue?

FYI, Error or not the solution builds and runs without any drama.

like image 612
mahfuz01 Avatar asked Mar 12 '23 20:03

mahfuz01


1 Answers

Check your ~/Views/web.config for the following settings.

<configuration>
  <system.web.webPages.razor>
    <pages pageBaseType="System.Web.Mvc.WebViewPage">
      ...
    </pages>
  </system.web.webPages.razor>
</configuration>

This is required for Visual Studio to recognize the types in your razor views.

Also ,

a. Unload and reload the project from the solution

b. Clean the solution

c. Exit Visual Studio, delete .user file in the project folder.

d. Open the solution again and build

like image 62
Ahsan Avatar answered May 01 '23 18:05

Ahsan