IntelliSense in Razor files (.cshtml) stopped work

2020-01-26 03:23发布

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>

18条回答
Anthone
2楼-- · 2020-01-26 04:14

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.

查看更多
We Are One
3楼-- · 2020-01-26 04:15

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.

查看更多
做自己的国王
4楼-- · 2020-01-26 04:17

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\14.0\ComponentModelCache

If you're using VS 2019, the version folder is named 16.0_<hash>.


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.

查看更多
爷的心禁止访问
5楼-- · 2020-01-26 04:17

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

查看更多
啃猪蹄的小仙女
6楼-- · 2020-01-26 04:19

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.

查看更多
欢心
7楼-- · 2020-01-26 04:19

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

查看更多
登录 后发表回答