Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IntelliSense in Razor files (.cshtml) stopped working

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>
like image 290
ridermansb Avatar asked Jan 23 '14 13:01

ridermansb


People also ask

Why is my IntelliSense not working?

If you find IntelliSense has stopped working, the language service may not be running. Try restarting VS Code and this should solve the issue. If you are still missing IntelliSense features after installing a language extension, open an issue in the repository of the language extension.

Is MVC better than Razor pages?

From the docs, "Razor Pages can make coding page-focused scenarios easier and more productive than using controllers and views." If your ASP.NET MVC app makes heavy use of views, you may want to consider migrating from actions and views to Razor Pages.

Is Cshtml the same as Razor?

razor helps you embed serverside code like C# code into web pages. cshtml is just a file extension. razor view engine is used to convert razor pages(. cshtml) to html.

What is @model in Razor page?

It is a self-contained class that represents the data and behaviour of a specific "view" or page. The view model pattern is used extensively in MVC application development, where it mainly represents data, but typically little behaviour. In Razor Pages, the PageModel is also the view model.

Why is IntelliSense not working in the razor file?

When intellisense stops working in the razor file, there's a good chance that the issue can be fixed in three steps: Close Visual Studio. Delete the solution user options file (<solution-name>.suo) Re-open the solution in Visual Studio.

Can I use IntelliSense in Blazor with Visual Studio 2022?

If you opt to use an external library such as MudBlazor for your Blazor projects, and are using Visual Studio 2022, you may well discover that you’re missing any kind of intellisense for the bundled styles (that come with the library). Taking MudBlazor specifically, it includes some handy utility classes for setting things like margins and padding.

Do you have no IntelliSense in your mudblazor projects?

You may be running into this problem If you opt to use an external library such as MudBlazor for your Blazor projects, and are using Visual Studio 2022, you may well discover that you’re missing any kind of intellisense for the bundled styles (that come with the library).

How to enable legacy Razor editor in ASP NET Core?

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. I had a similar situation, and then realized that the razor view wasn't included in my project.


5 Answers

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.

like image 44
Mike Avatar answered Oct 16 '22 23:10

Mike


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.

like image 71
silkfire Avatar answered Oct 17 '22 00:10

silkfire


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" />
like image 15
John Avatar answered Oct 16 '22 23:10

John


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>
like image 14
Kevin Hirst Avatar answered Oct 16 '22 23:10

Kevin Hirst


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.

like image 6
Philipo55 Avatar answered Oct 17 '22 00:10

Philipo55