86

Intellisense does not work in razor files:

enter image description here

In my web.conifg file (in the Views folder) is apparently correct:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <configSections>
        <sectionGroup name="system.web.webPages.razor" type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
            <section name="host" type="System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
            <section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
        </sectionGroup>
    </configSections>

    <system.web.webPages.razor>
        <host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
        <pages pageBaseType="System.Web.Mvc.WebViewPage">
            <namespaces>
                <add namespace="System.Web.Mvc" />
                <add namespace="System.Web.Mvc.Ajax" />
                <add namespace="System.Web.Mvc.Html" />
                <add namespace="System.Web.Routing" />
                <add namespace="System.Web.Optimization" />

                <add namespace="MvcSiteMapProvider.Web.Html" />
                <add namespace="MvcSiteMapProvider.Web.Html.Models" />

                <add namespace="DevTrends.MvcDonutCaching" />
            </namespaces>
        </pages>
    </system.web.webPages.razor>

    <appSettings>
        <add key="webpages:Enabled" value="false" />
    </appSettings>

    <system.webServer>
        <validation validateIntegratedModeConfiguration="false" />
        <handlers>
            <remove name="BlockViewHandler" />
            <add name="BlockViewHandler" path="*" verb="*" preCondition="integratedMode" type="System.Web.HttpNotFoundHandler" />
        </handlers>
    </system.webServer>
</configuration>
8
  • 1
    Try updating your nuget packages and also install VS2013 update 1. Jan 23, 2014 at 14:05
  • Try creating a brand new ASP MVC project and determine if intellisense works then. Jan 23, 2014 at 15:55
  • Works on new projects. this project is that it does not work!
    – ridermansb
    Jan 23, 2014 at 18:01
  • 1
    Divide and conquer, my friend. There's some important difference between your broken project and a new project. You need to figure out what that difference is. Jan 23, 2014 at 21:15
  • * I copied the web.config in the views folder to my project (did not work) * I checked the packages installed, dlls (and versions) and are all ok. * I tried to reinstall the packages using Update-Package -Reinstall (did not work)
    – ridermansb
    Jan 24, 2014 at 10:35

21 Answers 21

143

This is what worked for me after IntelliSense suddenly began to bug out and stopped colouring C# code correctly in between the HTML tags in my views:


Just delete the contents of the folder at %LOCALAPPDATA%\Microsoft\VisualStudio\16.0_<hash>\ComponentModelCache


enter image description here

As an additional step, you can optionally run the command DevEnv.exe /setup in Developer Command Prompt for VS (as an Administrator) if the above step doesn't resolve the issue.

12
  • 4
    This worked great for me on a fully up to date VS2015U1 just now (just deleting the cache) Feb 15, 2016 at 16:06
  • 4
    I just deleted the cache and it was fixed. Thanks.
    – ADM-IT
    Apr 27, 2016 at 13:16
  • 1
    After creating a new area this issue started occurring to me for its new views. I just deleted the cache files and reopened VS and now it's working. Thanks! Oct 18, 2016 at 17:25
  • 1
    Wow, super, thank you! The ComponentModelCache was my to-go place in VS 2013/15, I always had a shortcut to the folder handy: if anything breaks, delete the folder. VS 2017 is less prone to cache corruption, so I almost forgot about it. My problem was exactly same: no IS in Razor, and deleting the folder fixed it. Hope they'll get the cache coherent by VS 2042...
    – kkm
    Dec 29, 2018 at 20:51
  • 1
    Lost 2 hrs on this, it finally worked for me when after executing devenv /setup. Apr 13, 2020 at 10:29
25

When intellisense stops working in the razor file, there's a good chance that the issue can be fixed in three steps:

  1. Close Visual Studio
  2. Delete the solution user options file (<solution-name>.suo)
  3. Re-open the solution in Visual Studio.

Other solutions for intellisense options can be found here.

5
  • 12
    Sometimes step 1 is enough
    – ksaylor11
    Sep 14, 2015 at 16:38
  • 3
    I had to show hidden files in order to find my solution options (.suo) file
    – SteveB
    Sep 3, 2019 at 21:08
  • 1
    My .suo file was under /{solutionfolder}/.vs/{solutionname}/v16/ and was named .suo.
    – ctc
    Feb 28, 2021 at 19:49
  • Sounds like .suo was corrupted or something.
    – Jenna Leaf
    Mar 1 at 1:54
  • I just copy the bad pages out to somewhere outside the project, make some unimportant change, save, then delete the original from inside the project. Re-open the project, add those pages back as existing items. After that, intellisense comes right back as usual.
    – Jenna Leaf
    Mar 1 at 2:00
15

One cause for this could be if your wepages are set to version 3 for an mvc4 application, you can just change it to version 2 in the web.config app settings.

  <appSettings>
    <add key="webpages:Version" value="2.0.0.0" />
4
  • 1
    Indeed rolling back to version 2 brought intelligence back to life. But my System.Web,Webpages reference is actually version 3.0.0 and my project is MVC 5! That's weird Jul 30, 2015 at 18:10
  • I think mvc 5 ships with webpages version 3. That sounds correct. Perhaps your referenced dll's are not correct ?
    – John
    Jul 31, 2015 at 12:23
  • Checked the dlls also, versions match. Even creating a new MVC 5 project from scratch has broken intellisence. I have VS 2012 Update 4 installed + Web Tools 2013.1 Jul 31, 2015 at 13:20
  • 1
    Just found the issue..... it was Xamarin plug in which was causing the bug, and it's a known issue. Jul 31, 2015 at 16:59
14

I was experiencing this in Visual Studio 2013 after upgrading the project to MVC 5.2.3. The thing that worked for me was replacing the web.config in the "Views" folder with the following, since the NuGet package left that web.config with many MVC 4.0 references.

<?xml version="1.0"?>

<configuration>
  <configSections>
    <sectionGroup name="system.web.webPages.razor" type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
      <section name="host" type="System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
      <section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
    </sectionGroup>
  </configSections>

  <system.web.webPages.razor>
    <host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
    <pages pageBaseType="System.Web.Mvc.WebViewPage">
      <namespaces>
        <add namespace="System.Web.Mvc" />
        <add namespace="System.Web.Mvc.Ajax" />
        <add namespace="System.Web.Mvc.Html" />
        <add namespace="System.Web.Optimization"/>
        <add namespace="System.Web.Routing" />
        <add namespace="InvestureApps" />
      </namespaces>
    </pages>
  </system.web.webPages.razor>

  <appSettings>
    <add key="webpages:Enabled" value="false" />
  </appSettings>

  <system.webServer>
    <handlers>
      <remove name="BlockViewHandler"/>
      <add name="BlockViewHandler" path="*" verb="*" preCondition="integratedMode" type="System.Web.HttpNotFoundHandler" />
    </handlers>
  </system.webServer>
</configuration>
4
  • My views/webconfig file looks exactly like this, and still.. same problem :( Oct 21, 2016 at 23:11
  • 2
    This is what worked for me in combination with deleting the ComponentModelCache.
    – WillC
    Feb 28, 2017 at 17:42
  • Just updated the versions based on this and also deleted the ComponentModelCache
    – bets
    Jun 15, 2017 at 6:41
  • Finally! That worked for me too. Also in combination with deleting the ComponentModelCache after i updated the web.config in the views folder
    – Mevius
    Dec 12, 2018 at 18:22
6

I had this issue with Visual Studio 2017 - I went into the directory where the solution is located and deleted .the vs folder (it's a hidden folder) and that fixed my issue.

0
4

My project was upgraded from VS2012 to VS2013 and this solved the problem for me:

Change "webpages:Version" in the Web.config file from "1.0.0.0" to "2.0.0.0"

<appSettings>
    <add key="webpages:Version" value="2.0.0.0" />
1
  • Mine for some reason was set to 5 (in VS2017) changing to 3 appears to have solved the issue
    – bsod_
    Oct 15, 2018 at 10:44
4

In My case "Xamarin" (Mobile app development tools) is the problem. After uninstalled Xamarin, the razor Intellisense working fine.

http://forums.xamarin.com/discussion/24892...

3
3

I had the same issue. Although I'm using VS 2012, there is a download that applies to both VS 2013 and VS 2012. I've tried quite a few fixes (having to do with web.config, uninstalling/reinstalling MVC via NuGet, etc) but the only one that worked for me was installing this (again, for me, for VS 2012)

VS 2013 with ASP.NET and Web Tools 2013.1 http://www.asp.net/downloads

1
3

In my case the solution was setting the "Use legacy Razor editor for ASP.NET Core" inside tools>options>text editor>HTML>advanced to true.

1

I had a similar situation, and then realized that the razor view wasn't included in my project. As soon as I included it in the project (right click the view file and select Include in Project), Intellisense showed up.

1
  • 1
    I had this issue in VS Proffessional 2019 while working on an Umbraco project, and this solved the issue for me as well. Thanks for the tip! Dec 1, 2020 at 8:37
1

I just had to right click "Add to project" for my new view to pick up on Intellisense.

0
1

It looks that there are many reasons produce this problem.

In my case I copied some code/files from another project, after that the Intellisense doesn't work, this because I have different namespace in copied files so that makes Intellisense doesn't work. correct the namespace makes it works again.

1

In my case, none of the aboves worked, here is what I did to resolve my problem:

Load the project with VS and leave it, and then open the your-project-name.csproj with Notepad++ or whatever the Text editor you like and made some changes, like delete a Content tag(Don't worry, it will be back once you reinclude it in VS Solution Explorer), once you save your changes, the Visual Studio IDE will detect your changes and ask you for reloading the whole project, click on 'Yes' and my code IntelliSense back.

I'm using: Microsoft Visual Studio Professional 2019 Preview Version 16.3.0 Preview 2.0

Hope it helps.

0

Watch out if you have areas in your web application, there's yet another Web.config file in the Areas/Views folder and in my case this configuration file was the culprit.

Also, you may have to restart Visual Studio after making the changes to Web.config, rebuilding the solution doesn't seem to pick up the changes, at least it didn't for me.

1
  • just curious - how was the Web.config in the Areas/Views/ the culprit? Was the fix basically along the lines of Kevin Hirst answer lower? Jul 12, 2017 at 14:00
0

I just got through a very similar problem: an existing application wasn't providing intellesense for Razor views, but I could create a brand new application and it worked. I was able to solve the problem by using Scaffolding to create a new controller and views for an entity. The intellesense worked for the new entity, and it worked again for existing ones!

0

Installing ASP.NET and Web Tools 2013.1 for Visual Studio 2012 worked for me:

You might need to restart VS for this to work.

0

After lots of search and test I found that, without installing 2013 or any upgraded version you can still resolve this coloring issue for 2012. Installing "ASP.NET and Web Tools 2013.1 for Visual Studio 2012" solved this for me. Close VS 2012 and restart it after installing.

Dowload link is, https://www.microsoft.com/en-us/download/details.aspx?id=41532

It worked for me. Hope it works for you all.

0

In my case this fixed my problem i just change version value from 3 to 2. and its works for me.

0

Installing newer version (nightly build) of Resharper (2018.3 EAP 3) helped in my case.

0

I solved this problem by deleting the folder .vs in the solution path

0

None of the solutions above solved my case. Now I figured out it was because I did defragmentation. It caused this problem by moving and deleting some files. I re-installed Visual Studio. It works fine unless I perform defragmentation again. I hope this helps you

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.