Visual Studio 2015 Razor View MVC Types not recognized
Asked Answered
L

7

32

syntax error

I installed Visual Studio 2015 and rebooted. The "MVC" types are not recognized in 2015 but are still recognized in 2013. This is my "Views" web.config:

<configuration>
  <configSections>
    <sectionGroup name="system.web.webPages.razor" type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
      <section name="host" type="System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
      <section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, Version=2.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=4.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" />
      </namespaces>
    </pages>
  </system.web.webPages.razor>
Lampion answered 23/7, 2015 at 17:55 Comment(3)
looks like you're referencing pretty old version of System.Web.WebPages.Razor might not be a problem though.. but i'd create a new mvc project in 2015 and compare the versions. and also compare the root web.config also. Sometimes closing the view and reopening it helps too after you open a project the first timeVagrancy
Tried restarting VS, closing the view, etc. Not sure why it would be fine in VS2013 but broken in VS2015. I did submit feedback in VS2015 about it fyi.Lampion
It seems this is the only way for me. asp.net/mvc/overview/releases/…Bolanos
U
25

We believe these are occurring because you are currently using MVC 4, and MVC 4 tooling is not included with Visual Studio 2015. Only MVC 5 and MVC 6 tooling is included. If you are in fact using MVC 5 and seeing these issues, please do let us know. You can confirm you are using MVC 4 by opening packages.config and scrolling to the entry for Microsoft.AspNet.Mvc. If the version listed starts with "4", this means you are using MVC 4.

Having said that, we appreciate your feedback and the investment you have made in MVC 4. Based on yours and other customers’ feedback, we are looking into the possibility of making MVC 4 tooling available for Visual Studio 2015. In the meantime, your project will compile and run in Visual Studio 2015 despite the tooling issues. Alternatively, you can keep both Visual Studio 2013 and 2015 installed on your machine side-by-side. That way, you can use Visual Studio 2013 for MVC 4 projects and Visual Studio 2015 for MVC 5 and above projects.

Unbuckle answered 24/7, 2015 at 19:10 Comment(5)
This is correct and is a project in TFS that was created with MVC 4 and VS 2013. My VDN space in limited for my company development VM so it might not always be an option to keep VS 2013 indefinitely.Lampion
I have the same issue as Justin. But my references pointing to MVC 5 Assemblies. What' I have differently is that my views are alocated in another assembly. Any idea what that might be?Faery
It's a shame this didn't make it into the final version of 2015. Are there any plans to add it in an update?Wittgenstein
Does anyone happen to have the source for an official announcement from Microsoft on this?Inhabiter
I still have the issue with the following <package id="Microsoft.AspNet.Mvc" version="5.2.3" targetFramework="net46" />Albata
L
3

It didn't work for me. It seems that this issue has several root causes related to web.config.

One another problem was root web.config compilation version mismatch.

<compilation debug="true" targetFramework="4.5.2">

<httpRuntime executionTimeout="600" maxRequestLength="10240" requestValidationMode="2.0" targetFramework="4.5.2" />

If httpruntime version is different from the assembly's this may happen.

Laszlo answered 14/9, 2015 at 15:57 Comment(1)
The accepted answer did not fix my problem, but changing targetFramework from 4.5 to 4.5.2 did fix it.Capriccio
S
1

If you upgraded from MVC4 to MVC5: in Views/web.config change

   <host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />

to

   <host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
Sarmentose answered 18/11, 2016 at 12:40 Comment(0)
C
0

I think similar problem was described here - https://mcmap.net/q/82387/-mvc-razor-view-intellisense-broken-in-vs-2013-2015-2017/3350527. Old version of System.Web.Mvc in use (by VS 2015 opinion).

Cobble answered 23/7, 2015 at 18:12 Comment(1)
This is a slightly different issue about broken intellisense.Wittgenstein
S
0

I've tried many things to resolve this issue. To name a few:

  1. Checking and un-checking Tools->Text Editor->All Languages-> Auto List Members and Parameter information
  2. Restarting Visual Studio
  3. Deleting all sorts of file(s) in various folders:bin, *.sou, %AppLocacalData%\Temp and etc.

Nothing worked.

Then I've went to Control Panel and run Visual Studio setup and clicked 'Repair' button. After process has finished it offered to restart the machine and after that intellisense started to work again in razor views.

Strawser answered 25/11, 2015 at 16:12 Comment(1)
With all do respect, sir, it IS an answer to the question. This is what i actually done to get intellisense back to work. I just felt compelled to provide poor googling souls like me another chance to be able to intellisence again.Strawser
D
0

From Chris Zhao on asp.net: You could consider uninstalling VS 2015, and reinstall it again,and check whether "Web Developer tools" is selected [go into Custom during the installation to be sure it is checked.

I did this and it got rid of the red underlines under Viewbag.

Dews answered 20/1, 2016 at 23:18 Comment(2)
I've always been able to do this with MVC 5+ and VS2015, it's just the older MVC frameworks that I have issues with.Lampion
@Justin, For some reason, and I think it appeared after a VS 15 update, my MVC5 stuff that was displaying fine became problematic. Maybe it was changing the target .NET version. I don't know. It turns out that the Web Developer Tools that were installed were a RC version when I did the fix reinstall. The result was all of the things mentioned were fixed.Dews
A
0

I discovered that I needed to bump the version for the assemblies dealing with the config sections to 3.0.0.0 in the Views/Web.config file:

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

They were previously all 2.0.0.0.

Amund answered 18/11, 2016 at 16:16 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.