IntelliSense in Razor files (.cshtml) stopped working

Razorasp.net Mvc-5

Razor Problem Overview


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>

Razor Solutions


Solution 1 - Razor

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.

Solution 2 - Razor

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.

Solution 3 - Razor

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" />

Solution 4 - Razor

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>

Solution 5 - Razor

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.

Solution 6 - Razor

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...

Solution 7 - Razor

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" />

Solution 8 - Razor

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

Solution 9 - Razor

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.

Solution 10 - Razor

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.

Solution 11 - Razor

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

Solution 12 - Razor

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.

Solution 13 - Razor

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.

Solution 14 - Razor

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.

Solution 15 - Razor

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.

Solution 16 - Razor

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!

Solution 17 - Razor

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.

Solution 18 - Razor

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

Solution 19 - Razor

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionridermansbView Question on Stackoverflow
Solution 1 - RazorsilkfireView Answer on Stackoverflow
Solution 2 - RazorMikeView Answer on Stackoverflow
Solution 3 - RazorJohnView Answer on Stackoverflow
Solution 4 - RazorKevin HirstView Answer on Stackoverflow
Solution 5 - RazorPhilipo55View Answer on Stackoverflow
Solution 6 - RazorPalanikumarView Answer on Stackoverflow
Solution 7 - RazorJoshua LeonardView Answer on Stackoverflow
Solution 8 - RazorNigel GView Answer on Stackoverflow
Solution 9 - RazorlightofpastView Answer on Stackoverflow
Solution 10 - RazormkimmetView Answer on Stackoverflow
Solution 11 - RazorSheldonView Answer on Stackoverflow
Solution 12 - RazorEng. Samer TView Answer on Stackoverflow
Solution 13 - RazorJackView Answer on Stackoverflow
Solution 14 - RazorThorsten WestheiderView Answer on Stackoverflow
Solution 15 - RazorcsharpsqlView Answer on Stackoverflow
Solution 16 - RazorRoland WalesView Answer on Stackoverflow
Solution 17 - RazorNewUserView Answer on Stackoverflow
Solution 18 - RazorMuhammad Sohail NazarView Answer on Stackoverflow
Solution 19 - RazorVolodymyr KotyloView Answer on Stackoverflow