MVC Razor view Intellisense broken in VS 2013/2015/2017

后端 未结 22 2224
失恋的感觉
失恋的感觉 2020-11-27 16:52

I have an existing project written in VS2010 which when loaded in VS2010 works perfectly.

When I load this same project in VS2013 the MVC Razor views contain lots of

相关标签:
22条回答
  • 2020-11-27 17:18

    In upgrading from MVC 3 to 5, I found that in my root directory Web.config that the appSettings key webpages:version was set to 2.0.0.0. Changing this to 3.0.0.0 fixed this issue.

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

    0 讨论(0)
  • 2020-11-27 17:19

    I have tried almost every solutions but did not get intellisense and at the end I found a solution:

    1. Go to Solution Explorer
    2. Right click on .cshtml file or any view file
    3. Select "Open With" option and make HTML Editor(Default) set as default
    0 讨论(0)
  • 2020-11-27 17:25

    I am using VS 2017 professional, and I tried almost every answer on this post, and also those on that post, but nothing worked for me. Yesterday I updated VS, to version 15.2 (26430.6) Release, and intellisense is back in my cshtml files!

    0 讨论(0)
  • 2020-11-27 17:27

    This question has been resolved, but I'm adding this for future folks, since none of the above worked for me:

    Try running Visual Studio as an administrator.

    Somehow when I tried to delete my nuget packages (which contain all the required references, such as System.Web.Mvc, I was told I need permission from MyPC\Me. Ridiculous! (I am the only user and only admin...) In any case, running as an admin at least let me access those files which fixed intellisense.

    0 讨论(0)
  • 2020-11-27 17:27

    I ran into a similar problem. I had an MVC 5 project created with VS2015 Community Edition that I needed to work on with VS2013 Ultimate. Removing the following <system.codedom></system.codedom> block from the root web.config file is what finally allowed IntelliSense to work again in my Razor views on VS2013.

    <system.codedom>
      <compilers>
        <compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:6 /nowarn:1659;1699;1701" />
        <compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:14 /nowarn:41008 /define:_MYTYPE=\&quot;Web\&quot; /optionInfer+" />
      </compilers>
    </system.codedom>
    
    0 讨论(0)
  • 2020-11-27 17:28

    I considered editing @ChrisMoschini's post, but thought it was different enough. My issue was that I started a new MVC5 application, and blindly copied over too many web.config settings from an old MVC3 project I wanted to use as a template/starting point. Doing this caused me to have some invalid versions referenced in my web.config.

    To fix, I created another new MVC5 project and made sure the following config values in my bad project matched the vanilla, unmodified MVC5 app. Again, do not blindly copy these version numbers. Just make sure they match a vanilla MVC app of the version that you're trying to get to work

    in root web.config:

    <appSettings>
        ...
        <add key="webpages:Version" value="3.0.0.0"/> 
        ...
    </appSettings>
    <system.web>
        ...
        <compilation debug="true" targetFramework="4.5.1"/>
        <httpRuntime targetFramework="4.5.1"/>
        ...
    </system.web>
    

    in the Views\Web.config:

    <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>
    
    
    <system.web.webPages.razor>
      ...
      <host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=5.2.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
      ...
    </system.web.webPages.razor>
    
    0 讨论(0)
提交回复
热议问题