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

后端 未结 22 2207
失恋的感觉
失恋的感觉 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:29

    A few of my projects had this issues for months. I tried so many workarounds and nothing worked. The issues seemed to be with the projects: the same project will have Intellisense issue across all PCs with Visual Studio. Finally I came through this post: http://www.dennisonpro.info/managing-intellisense-in-razor-views-with-mvc-5-using-custom-builds-in-visual-studio-2013/

    In our case the cause was the output directory of all those projects were changed to other than "bin\". By changing the OutputPath back to "bin\" (and cleaning the project, closing then re-opening Visual Studio), I got Intellisense back.

    The post referenced above also provided a workaround to maintain a separate output directory while still having Intellisense.

    Hope this helps someone someday.

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

    A combination of the following helped to solve the problem for me:

    • Creating a new MVC Project
    • Comparing the versions in the views web.config files of the existing and new projects
    • Fixing the versions accordingly (see below)
    • Deleting all files in the bin folder
    • Cleaning the solution
    • and finally rebuilding the solution
    <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.2.3.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" />
          </namespaces>
        </pages>
      </system.web.webPages.razor>
    
      <appSettings>
        <add key="webpages:Version" value="3.0.0.0"/>
        <add key="webpages:Enabled" value="false" />
      </appSettings>
      [...]
    
    0 讨论(0)
  • 2020-11-27 17:33

    I have had this over and over again; I'm on my third new project, and it's driving me mad! I think I may have found the reason for the problem. I'd added files, but not included them in Visual Studio. So I've now chosen to view all files:

    Then for all my folders which I'd added, I include them:

    The problem is that this only seems to show up when you open an MVC site as a project, and not when you open it as a website.

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

    I upgraded an MVC3 project to MVC5, and did everything I could to avoid the only true answer to this problem that Microsoft recommends:

    Start over with a new Project, and port the resulting bits over into your existing project.

    That process is a big waste of time, and it seems like Microsoft should make a real upgrade path viable, but I am here to tell you the problem here is an emotional one not technical: You really do need to just create a new MVC5 project, and replace the following with the result of that new MVC5 project:

    \Packages\*
    \Project\Project.csproj
    \Project\packages.config
    \Project\Web.Config
    \Project\Views\Web.Config
    \Project\Areas\*\Views\Web.Config
    

    If you don't you'll just go around in circles for eternity trying to find the one setting that's blowing things up. In our case, I had the Web.Configs all identical to the newly-created, Razor Intellisense-working MVC5 project, I had run every variety of upgrade tool I could find, you name it. Intellisense refused to work.

    After just blowing away the .csproj and web.configs etc, Intellisense came magically back to life. Diffing the 2 sides, none of the answers that I've found anywhere match with what I'm seeing. Web.Configs are almost identical, and the bits that are different should be irrelevant. The main change is really what's in \Packages\ - a lot of older Razor, MVC, and WebPages dlls gone. That could be the trick, but skip that and save yourself a lot of time: Just make a new MVC5 project and dump the above-listed files over. It's the only sane method of upgrading.

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

    I am using visual studio 2012. I tried all of the above but finally the problem is resolved by installing :

    ASP.NET and Web Tools 2013.1 : http://blogs.msdn.com/b/webdev/archive/2013/11/18/announcing-release-of-asp-net-and-web-tools-2013-1-for-visual-studio-2012.aspx

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

    I had this issue for six months and just realized that I needed to move my @model directives to the top of the pages. I previously had them inside code blocks.

    0 讨论(0)
提交回复
热议问题