The name does not exist in the current context (ra

2019-09-12 17:55发布

问题:

I'm having a few issues with razor and yet again it's stressing me out.

I opened a project which is littered with Red Squiggles within the razor. This is very much a challenge as I'm a Webforms developer moving over to MVC.

I'm running visual studio 2015 enterprise.

At first I thought it might be a version issue but all seems good. WebConfig seems up to date. I'm at a loss, and in need of guidance. Any help greatly appreciated!

///EDITS

Views web.config.

  <add namespace="System.Web.Mvc" />
  <add namespace="System.Web.Mvc.Ajax" />
  <add namespace="System.Web.Mvc.Html" />
  <add namespace="System.Web.Routing" />
  <add namespace="System.Web.Optimization" />

It looks like I'm missing the razor namespace. I cannot actually add this in the references.

回答1:

Locate section <system.web.webPages.razor> in you web.config. This configuration file can be found under Views -> web.config. If you have version 4.0.0.0 for System.Web.Mvc.MvcWebRazorHostFactory then change it to Version=5.0.0.0. It should look like below:

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

Note: Make sure you call all the views in Visual studio and re-open them.



回答2:

That looks to me like your UI project is missing the MVC and Razor assembly references.

Check the references for

System.Web.MVC

System.Web.Razor

System.Web.Webpages

System.Web.Webpages.Razor