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条回答
欢心
2楼-- · 2020-01-26 03:54

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.

查看更多
smile是对你的礼貌
3楼-- · 2020-01-26 03:54

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

查看更多
放我归山
4楼-- · 2020-01-26 03:54

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.

查看更多
虎瘦雄心在
5楼-- · 2020-01-26 03:58

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.

查看更多
Explosion°爆炸
6楼-- · 2020-01-26 03:58

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

查看更多
成全新的幸福
7楼-- · 2020-01-26 04:01

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!

查看更多
登录 后发表回答