Why doesn't Visual Studio 2019 recognize Razor syntax from an ASP.NET MVC 4 project? RRS feed

  • Question

  • User-1128090897 posted

    Hi folks,

    Visual Studio 2019 is not recognizing Razor template engine syntax, for some reason. I'm working on an older ASP.NET MVC 4 project. Certain syntax, such as @model and ViewBag show up with red error underlines. Essentially, all of my Razor files are marked entirely with red error lines and are effectively impossible to do any real work within until I can fix this.

    I've been dealing with this issue for awhile, and am finally tasked with some heavy refactoring of an older ASP.NET MVC 4 project. This issue for me was no big burden for tiny modifications, but now I'm needing proper intellisense within my razor files, etc.

    So, how can I get Visual Studio to understand and properly analyze my Razor template files for this older project?

    I found many answers on StackOverflow saying to make various changes to Web.config files, but none were very clearly explained enough for me, I suppose. I do figure the error lies somewhere within a Web.config, but how can I make the  proper change?

    Thanks! Also, below are the package versions from my packages.config, as well as a screen shot of a Razor file for an example of what I'm seeing.

    <?xml version="1.0" encoding="utf-8"?>
      <package id="Agent.Data" version="0.3.1" targetFramework="net46" />
      <package id="Agent.Entity" version="0.2.10" targetFramework="net46" />
      <package id="Antlr" version="" targetFramework="net45" />
      <package id="Aspose.Cells" version="" targetFramework="net472" />
      <package id="bootstrap" version="4.1.1" targetFramework="net46" />
      <package id="EntityFramework" version="6.2.0" targetFramework="net472" />
      <package id="FluentValidation" version="" targetFramework="net45" />
      <package id="FluentValidation.MVC4" version="" targetFramework="net45" />
      <package id="HubSpot.Tether" version="1.1.1" targetFramework="net45" />
      <package id="jQuery" version="3.0.0" targetFramework="net45" />
      <package id="LinqKit" version="1.1.16" targetFramework="net472" />
      <package id="lodash" version="4.17.4" targetFramework="net45" />
      <package id="Microsoft.AspNet.Mvc" version="4.0.30506.0" targetFramework="net45" />
      <package id="Microsoft.AspNet.Providers.Core" version="1.2" targetFramework="net45" />
      <package id="Microsoft.AspNet.Providers.LocalDB" version="1.1" targetFramework="net45" />
      <package id="Microsoft.AspNet.Razor" version="2.0.30506.0" targetFramework="net45" />
      <package id="Microsoft.AspNet.Web.Optimization" version="1.1.1" targetFramework="net45" />
      <package id="Microsoft.AspNet.WebApi" version="5.0.0" targetFramework="net45" />
      <package id="Microsoft.AspNet.WebApi.Client" version="5.0.0" targetFramework="net45" />
      <package id="Microsoft.AspNet.WebApi.Core" version="5.0.0" targetFramework="net45" />
      <package id="Microsoft.AspNet.WebApi.WebHost" version="5.0.0" targetFramework="net45" />
      <package id="Microsoft.AspNet.WebPages" version="2.0.30506.0" targetFramework="net45" />
      <package id="Microsoft.Web.Infrastructure" version="" targetFramework="net45" />
      <package id="Newtonsoft.Json" version="5.0.8" targetFramework="net45" />
      <package id="Ninject" version="" targetFramework="net45" />
      <package id="Ninject.MVC3" version="" targetFramework="net45" />
      <package id="Ninject.Web.Common" version="" targetFramework="net45" />
      <package id="Ninject.Web.Common.WebHost" version="" targetFramework="net45" />
      <package id="Ninject.Web.WebApi" version="" targetFramework="net45" />
      <package id="Ninject.Web.WebApi.WebHost" version="" targetFramework="net45" />
      <package id="octicons" version="3.5.0" targetFramework="net45" />
      <package id="popper.js" version="1.14.0" targetFramework="net46" />
      <package id="Portal" version="2.4.1-alpha" targetFramework="net472" />
      <package id="System.ComponentModel.Annotations" version="4.5.0" targetFramework="net472" />
      <package id="Tablesorter" version="2.25.4" targetFramework="net45" />
      <package id="WebActivatorEx" version="2.0" targetFramework="net45" />
      <package id="WebGrease" version="1.5.2" targetFramework="net45" />


    Friday, January 10, 2020 10:10 PM

All replies

  • User409696431 posted

    Create a new MVC project in VS2019.  It understands cshtml syntax just fine.  Compare the web.config it creates with the one in your existing project and see if you can find a difference that explains the problem.

    Saturday, January 11, 2020 1:28 AM
  • User-17257777 posted

    Hi rcoleils2,

    You can try to delete the content under this folder,


    For more details, you can refer to https://stackoverflow.com/a/33612416/11965297

    Best Regards,

    Jiadong Meng

    Monday, January 13, 2020 7:20 AM
  • User753101303 posted


    Launch maybe the setup and make sure MVC4 is installed. AFAIK the default web development workload uses MVC 5.

    If not solved showing the error message could perhaps help. I assume it wokrs fine for a new project that uses MVC 5 ?

    Thursday, January 16, 2020 7:55 AM