Razor Intellisense Not Working VS2010 SP1Rel MVC3 from WPI Win7 x64

17,834

Solution 1

I know it's been a while since the last post, but I fixed mine by uninstalling MVC 2 and MVC2 VS Tools, and only leaving MVC 3 installed.

Solution 2

If you have MVC4 and MVC3 installed you need to add this to appsettings in web.config (in root and in Views folder) to use MVC3

<appsettings>
    <add key="webpages:Version" value="1.0.0.0">
    ...
</appsettings>

Also check your references in root web.config, they should included these versions

<add assembly="System.Web.Helpers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.Routing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.WebPages, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />

Re-open your solution for settings to take effect

Solution 3

I just wasted 2 hours of my life on this. What happened to me is that the web.config file got checked in wrong and was no longer Unicode UTF8. When VS 2010 opened the solution, it checks the web.config file for the appsettings:

<add key="webpages:Version" value="2.0.0.0" />
<add key="webpages:Enabled" value="true" />

Since the file couldn't be read by normal means, it just skipped it entirely, causing VS to think you needed to reinstall MVC... I just wanted to post this in case someone else runs into the same problem for an easy fix.

Solution 4

Razor Intellisense work with Razor Editor

Check if it is selected as default editor, For this do

  • Right Click on view file (.cshtml)
  • Select Open With...
  • Check Razor editor Select as default
  • if not, uninstall mvc3 from control panel reinstall it.

Again check files must be opened in Razor Editor. I have done this and its working now.

Solution 5

I fixed it by right clicking on the cshtml file and selecting "View Markup".

Share:
17,834
James Tan
Author by

James Tan

Updated on August 23, 2022

Comments

  • James Tan
    James Tan over 1 year

    I have Visual Studio 2010 /SP1 / MVC 3 (With April Tools Update) installed on a machine with a fresh install of Windows 7 64-bit Professional.

    I do not have resharper installed. I never installed an RC or Beta of anything on this new OS Install.

    My install steps were as follows:

    1. Install Visual Studio Professional.
    2. Install Web Platform Installer.
    3. Install Visual Studio SP1 from WPI.
    4. Install Microsoft ASP.net MVC 3 (with April Tools Update)
    5. Install Productivity Power Tools

    Help > About Microsoft Visual Studio shows:

    Microsoft Visual Studio 2010 Version 10.0.40219.1 SP1Rel

    Microsoft .NET Framework Version 4.0.30319 SP1Rel

    System.Web.Mvc.dll file version shows: 3.0.20105.0

    Once installed I did the following:

    1. Open Visual Studio.
    2. File > New Project
    3. Choose "ASP.Net MVC 3 Web Application".
    4. On the "New ASP.NET MVC 3 Project" dialog. I chose "Internet Application", "Razor" View Engine. Hit OK.

    Within the project here is the behavior:

    1. Open any cshtml file and Razor @blocks are not highlighted.
    2. Intellisense gives html snippets as options in and outside of razor blocks but does not recognize Html helpers or models etc within them.
    3. The project builds.
    4. You can run the project and everything works when built. Razor views are rendered normally.

    Does anyone know a definitive set of prerequisites to have Razor Intellisense working? Something I can diff between the other Win7 64-bit machines that have Razor Intellisense working and the 2 that have this issue? Registry entries? Are there any Visual Studio logs that can help debug this? After hours of frustration and reading every Razor Intellisense post and question I have run across without coming up with anything that works I am just hoping for some new thoughts on what to troubleshoot/try next.

    Thanks for any help on this.

  • James Tan
    James Tan almost 13 years
    Ya in my case it was a brand new install of Win7 Ultimate 64-bit. VS 2010 RTM then WebPlatformInstaller VS 2010 SP1. I even reformatted and tried again. The VS team is working on it. They were unable to reproduce with Win7 Pro 64-Bit. That is what I ended up doing is reformatting and using Win7 Pro 64-bit.
  • Dan
    Dan over 12 years
    Didn't he say he has VS 2010 SP1?\
  • James Tan
    James Tan about 12 years
    I will have to try this on a fresh install of Win 7 Ultimate 64bit. My solution was to install Windows 7 Professional 64bit. Following the same process on Win7 Pro everything worked so I left it at that. I did this with 3 machines following exactly the same steps from notes. For me it was definitely a Win 7 Ultimate 64-bit specific problem.
  • James Tan
    James Tan about 12 years
    In my case this was not the answer. The editor was associated with cshtml, it just wasn't functioning correctly.
  • Ozzie Perez
    Ozzie Perez about 12 years
    I had MVC2, MVC3, and MVC4 Beta installed and autocomplete wasn't working with strongly-typed razor views. After I uninstalled MVC2, MVC2 VS Tools, MVC4, and MVC4 VS Tools, leaving only MVC3 installed, it all worked again. Voted this up. Thanks.
  • Jeremy Holovacs
    Jeremy Holovacs almost 12 years
    It seems I have this problem. What did you do to correct it?
  • MajorRefactoring
    MajorRefactoring almost 12 years
    This is what worked for me. I uninstalled MVC2 and MVC2 Tools, and it still wasn't working, then I added the <add key="webpages:Version" value="1.0.0.0"> config item, closed and reopened the solution and that seemed to fix it. I now have MVC3 and MVC3 tools, plus MVC4 and MVC4 tools, and it's working fine.
  • Zane
    Zane almost 12 years
    For me it was sufficient to leave MVC2 and MVC4 installed and just make the changes to the web.config files. I also closed and reopened the solution.
  • Phil Cooper
    Phil Cooper over 11 years
    This worked for me but I only needed to change the appSettings value. My issue was upgrading MVC but the project still had 1.0.0.0 and I needed 2.0.0.0. Boom.
  • Daniel Lorenz
    Daniel Lorenz over 11 years
    Ah, that is interesting. I wouldn't expect that version to cause an issue, too! :)
  • Alexandre Leites
    Alexandre Leites over 11 years
    The intellisense on ServiceStack Razor works when I set it to 2.0.0.0. Thanks :-) I'm eager to see intellisense on servicestack razor's model too, in which the ServiceStack Razor author is planning to solve in the future
  • Simon Linder
    Simon Linder about 10 years
    I often had VS 2010 crashes when opening a *.cshtml file size we updated to WebPages 2.0. Thanks to webpages:Enabled true VS doesn't crash anymore. Thx.
  • Benjamin Anderson
    Benjamin Anderson about 10 years
    This also applies to later versions of Visual Studio