MVC Razor view Intellisense broken in VS 2013/2015/2017
Asked Answered
B

23

48

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 errors as if the config file is missing from the views folder.

It appears to have not loaded the Razor editor correctly using the config files from both the root and the views folder and instead gives me errors like ...

The name 'model' does not exist in the current context

and ...

'System.Web.WebPages.Html.HtmlHelper' does not contain a definition for 'LabelFor' 
and no extension method 'LabelFor' accepting a first argument of type 
'System.Web.WebPages.Html.HtmlHelper' could be found 
(are you missing a using directive or an assembly reference?)

...

Any idea what would cause this?

Edit: Config files as requested ....

From main web.config file (not all of it as it's way too big to post)

<runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
        <dependentAssembly>
            <assemblyIdentity name="Ninject" culture="neutral" publicKeyToken="c7192dc5380945e7" />
            <bindingRedirect newVersion="3.0.0.0" oldVersion="0.0.0.0-3.0.0.0" />
        </dependentAssembly>
        <dependentAssembly>
            <assemblyIdentity name="Microsoft.Practices.EnterpriseLibrary.Validation" culture="neutral" publicKeyToken="31bf3856ad364e35" />
            <bindingRedirect newVersion="5.0.505.0" oldVersion="0.0.0.0-5.0.505.0" />
        </dependentAssembly>
        <dependentAssembly>
            <assemblyIdentity name="System.Web" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
            <bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
        </dependentAssembly>
        <dependentAssembly>
            <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
            <bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="3.0.0.0" />
        </dependentAssembly>
        <dependentAssembly>
            <assemblyIdentity name="Microsoft.Practices.ServiceLocation" publicKeyToken="31bf3856ad364e35" culture="neutral" />
            <bindingRedirect oldVersion="0.0.0.0-1.2.0.0" newVersion="1.2.0.0" />
        </dependentAssembly>
    </assemblyBinding>
</runtime>

Config file in "~/Views/" ...

<?xml version="1.0"?>  
<configuration>
    <configSections>
        <sectionGroup name="system.web.webPages.razor" type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
            <section name="host" type="System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
            <section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, Version=1.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=3.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="Emedia.Common.Mvc.Views.Helpers"/>
                <add namespace="Emedia.Common.Mvc.Views.Extensions"/>
        <add namespace="Emedia.Common.Utilities"/>
        <add namespace="Emedia.Common.Utilities.Extensions"/> 
        <add namespace="Emedia.Common.Mvc.Controllers.Helpers"/>
                <add namespace="Emedia.Resources.Service"/>
        <add namespace="Emedia.Subscriber.Controllers"/>
        <add namespace="Emedia.Subscriber.Controllers.ViewModels"/>
            </namespaces>
        </pages>
    </system.web.webPages.razor>

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

    <system.web>
        <httpHandlers>
            <add path="*" verb="*" type="System.Web.HttpNotFoundHandler"/>
        </httpHandlers>
        <pages
            validateRequest="false"
            pageParserFilterType="System.Web.Mvc.ViewTypeParserFilter, System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
            pageBaseType="System.Web.Mvc.ViewPage, System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
            userControlBaseType="System.Web.Mvc.ViewUserControl, System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
            <controls>
                <add assembly="System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" namespace="System.Web.Mvc" tagPrefix="mvc" />
        </controls>
    </pages>
</system.web>

<system.webServer>
    <validation validateIntegratedModeConfiguration="false" />

    <handlers>
        <remove name="BlockViewHandler"/>
        <add name="BlockViewHandler" path="*" verb="*" preCondition="integratedMode" type="System.Web.HttpNotFoundHandler" />
    </handlers>
</system.webServer>

Butadiene answered 3/4, 2014 at 8:50 Comment(2)
Can you post your configs?Snath
there ya go ... obviously not the whole lot of the main config file but the key bits, our main config file is about 500 lines and contains some company sensitive stuff I can't give you (like connection strings)Butadiene
C
62

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>
Crimpy answered 27/8, 2014 at 13:24 Comment(6)
That was correct for me, helped changing version in: <add key="webpages:Version" value="3.0.0.0"/>Provincialism
I can't be certain this fixed my problem....but I've +1'ed it just in case. At any rate, after making these changes...no effect. But after closing and re-opening the solution/program after making these changes....it appears to be working.Irina
I checked the version numbers, but no change for meLinson
Fantastic. This worked for me also. I was just missing the webpages:Version bit from the root web.config. Adding that did the trick.Blinker
@Crimpy although this didn't solve my situation, it's reasonably safe to say it's unlikely anyone else would have the specific issue I had so I've decided to flag this answer as the solution :)Butadiene
thanks, for some reason <httpRuntime targetFramework="4.5.1" /> had been commented out of my gobal web.config. it seems it was an automatic comment done by microsoft so not sure why that is happening when upgrading.Belting
K
16

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.

Kipp answered 28/6, 2014 at 16:33 Comment(2)
I have tried this but heard positive things, it didn't solve my problem but may help others.Butadiene
This worked for my ASP.Net webforms project which I've just migrated from VS2008 to VS2013... It seemed to have changed the build path to: WORKSPACE\PrecompiledWeb\PROJECTNAME when I migrated the project but it works perfectly again now I've changed it back to WORKSPACE\PROJECTNAME\binClassroom
H
8

MS says that for VS2013 "Intellisense for Razor (CSHTML and VBHTML) files is limited to HTML markup."

But if you add these two lines inside each .cshtml the intellisense will work again for MVC3 in VS2013:

@using System.Web.Mvc.Html
@inherits System.Web.Mvc.WebViewPage<dynamic>

Instead of dynamic you can put your Model's type.

Huai answered 26/2, 2015 at 21:45 Comment(0)
B
7

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.

Beefcake answered 25/7, 2014 at 0:52 Comment(3)
This will work, but it takes a lot of effort. I almost had to go to that route (I was 5 minutes away from doing it). I found a shortcut that just so happen to work for my scenario and have posted an answer on this question. It may not work in all scenarios though. #22832935Crimpy
All the other answers seem to state "hack the config like this" the fact is, this stuff should just work out of the box, in my case vs was broken, when I asked this question but having had it since on other working pc's with good VS installs this is the best path and it stops people from having parts of a solution by ensuring they have microsoft's recommended solution. It is however worth noting that some extra lines may need to be added to the new config files after this process.Butadiene
I'm on my FOURTH new build. I was fine before I upgraded to VS 2015 and MVC 5. I've wasted a man-week so far. Aaaargh!Catholicon
S
6

I have recently solved this problem myself. I upgraded from MVC4 to MVC5 (specifically 5.1). Upgrading to a newer version of MVC caused this havoc and I spent hours trying to solve it. Minor changes to the Web.Config file fixed the intellisense issue!

You said the project works in VS2010, but not 2013? See this answer here.

I recommend upgrading to MVC5. It's not painful and the upgrade should be pretty seamless.

If you upgrade to MVC5 and you're still not getting intellisense, you need to update the Web.Config file manually as the upgrade may not do this correctly!

Here's a modified version of your Web.conifg in the /Views folder that should reflect changes for MVC5.

<?xml version="1.0"?>  
<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.1.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="Emedia.Common.Mvc.Views.Helpers"/>
            <add namespace="Emedia.Common.Mvc.Views.Extensions"/>
    <add namespace="Emedia.Common.Utilities"/>
    <add namespace="Emedia.Common.Utilities.Extensions"/> 
    <add namespace="Emedia.Common.Mvc.Controllers.Helpers"/>
            <add namespace="Emedia.Resources.Service"/>
    <add namespace="Emedia.Subscriber.Controllers"/>
    <add namespace="Emedia.Subscriber.Controllers.ViewModels"/>
        </namespaces>
    </pages>
</system.web.webPages.razor>

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

<system.web>
    <httpHandlers>
        <add path="*" verb="*" type="System.Web.HttpNotFoundHandler"/>
    </httpHandlers>
    <pages
        validateRequest="false"
        pageParserFilterType="System.Web.Mvc.ViewTypeParserFilter, System.Web.Mvc, Version=5.1.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
        pageBaseType="System.Web.Mvc.ViewPage, System.Web.Mvc, Version=5.1.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
        userControlBaseType="System.Web.Mvc.ViewUserControl, System.Web.Mvc, Version=5.1.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
        <controls>
            <add assembly="System.Web.Mvc, Version=5.1.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" namespace="System.Web.Mvc" tagPrefix="mvc" />
    </controls>
</pages>
</system.web>
<system.webServer>
<validation validateIntegratedModeConfiguration="false" />

<handlers>
    <remove name="BlockViewHandler"/>
    <add name="BlockViewHandler" path="*" verb="*" preCondition="integratedMode" type="System.Web.HttpNotFoundHandler" />
</handlers>
</system.webServer>

If upgrading is not an option, then I'm afraid you will need to continue using VS2010 if you want intellisense support for MVC3. However, I strongly suggest upgrading to MVC5.

Sine answered 8/4, 2014 at 8:8 Comment(2)
This doesn't resolve the problem, I have an MVC 5.1 version on another branch with the same problem.Butadiene
Wardy, did you make sure the versions for MVC is right in each of those views? That fixed it for me.Amorita
R
5

For anyone else who might stumble across this I didn't find any of the previous answers to really solve my problem or not pertain to it. Anyways the way that solved this for me and made intellisense work again was to go to my bin folder and delete all the files in there and then clean/rebuild and it was fixed.

Ribera answered 25/11, 2014 at 20:57 Comment(0)
F
5

When I created a new project intellisense worked fine, but for some reason it didn't work in our current project. The only difference I found in the Views/Web.config file was that ours had MVC version 5.2.0.0 and a new project had 5.0.0.0. What worked for us was to change this:

<host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc,
     Version=5.0.0.0, Culture=neutral, PublicKeyToken=123JHJF56AD364E35" />

to this:

<host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc,
     Version=5.2.0.0, Culture=neutral, PublicKeyToken=123JHJF56AD364E35" />
Farley answered 25/1, 2015 at 1:59 Comment(1)
In my case this happened after updating mvc through nuget. For some reason nuget fails to update the web.config file in views folder.Ori
T
2

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.

Tigress answered 21/12, 2014 at 21:58 Comment(0)
I
2

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>
  [...]
Inexpugnable answered 23/7, 2015 at 7:58 Comment(0)
C
2

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:

enter image description here

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

enter image description here

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.

Catholicon answered 6/5, 2016 at 15:3 Comment(0)
B
1

I eventually had a bunch of other problems on my pc because of a network server crash and ended up reinstalling visual studio.

This apparently solved the problem ... i have no idea how but it did.

I wonder if maybe in my case it was simply just a faulty installation rather than the typical problem.

For that reason I will mark this as the answer but +1 all other replies as they are potentially good answers to this problem.

I did however find that Microsoft clearly states visual studio 2013 does not support intellisense on lower versions of MVC than 4 so if you are using MVC 3 upgrade your project if you are using a newer version of MVC and nothing else here works try reinstalling visual studio.

Also worth noting ... MVC is now a nuget package so don't install MVC from the download redist allow VS to figure that out for you.

Butadiene answered 18/7, 2014 at 9:58 Comment(2)
Have you got a link to where MS states it doesn't support intellisense for MVC3?Dextroglucose
This seems to be commonly accepted, can't remmeber where I got this from but the source was definitely Microsoft originall, for example ... #19567735 Some of the "hacks" help but often don't completely resolve the problem.Butadiene
G
1

In my case I moved all of the views from an Area to the root Views folder, so I think VS got confused as to where my web.config was. I renamed it to Web.config, from web.config and then made an edit to the contents of the config (such as changing the version number of the razor host factory dll from 5.2.2.0 to 5.2.3), but then changed it back.

Then I went on a walk for about 30 minutes and came back and restarted VS and it was fixed!

Genovese answered 5/8, 2015 at 21:44 Comment(0)
U
1

In MVC 5 if you try to add an area by just adding a folder under Areas and sub folders for Controllers, Views, Models, etc. you won't have the *AreaRegistration.cs file that registers the area, or the web.config in views that enable VS to understand the razor elements that you include in your views. The result is that intellisense doesn't work in your view for things like ViewBag. If you have working examples of those files in other areas you can copy them in and update as appropriate - or you can start over with your Area by right clicking on Areas and doing an Add - Area which will create those files for you.

Unfailing answered 18/8, 2015 at 17:37 Comment(0)
F
1

I've changed from

<host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc,
 Version=5.2.0.0, Culture=neutral, PublicKeyToken=123JHJF56AD364E35" />

to this:

<host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc,
 Version=5.0.0.0, Culture=neutral, PublicKeyToken=123JHJF56AD364E35" />

And it worked!

Foresail answered 2/4, 2016 at 21:48 Comment(0)
K
1

Update the NuGet Packages using Package Manager console in Tool, Library package Manager..

In command line.. PM> Update-Package This will update NuGet packages and verify the current version of System.web.MVC and update this version in web.config file under Views folder.

<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" />
        <add namespace="System.Web.Webpages"/>
      </namespaces>
    </pages>
  </system.web.webPages.razor>

Close the solution and Reopen.

Hope this works !!!

Kummerbund answered 7/6, 2017 at 17:27 Comment(1)
Works well used together with @viggity's answer. One remark : "System.Web.Webpages" is actually "System.Web.WebPages".Desrochers
C
0

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.

Chitchat answered 24/1, 2015 at 19:54 Comment(0)
D
0

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

Duff answered 27/8, 2015 at 7:47 Comment(0)
C
0

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>
Cytogenesis answered 26/11, 2015 at 2:40 Comment(0)
S
0

Try setting the CopyLocal property of the System.Web.Mvc reference to true. Sometimes this helps with Intellisense.

Sundog answered 19/1, 2016 at 14:57 Comment(0)
M
0

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!

Mephistopheles answered 15/5, 2017 at 6:13 Comment(0)
A
0

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
Alas answered 6/6, 2017 at 11:51 Comment(0)
I
0

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>

Issus answered 26/9, 2017 at 14:46 Comment(0)
C
0

I updated VS2013 to update 5 and it is fixed.

Cleptomania answered 18/4, 2023 at 17:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.