Razor语法在编译之前在View中给出错误(无智能感知) [英] Razor Syntax gives errors in View before compiling (No intellisense)

查看:364
本文介绍了Razor语法在编译之前在View中给出错误(无智能感知)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在浏览NuGet软件包列表,我正在更新诸如bootstrap,jQuery等的所有东西,但是当我这样做时,我不经意地更新了Microsoft.Owin 和另一个软件包(可能已经是EF或其他东西),这是一个主要版本更新... woops。



我不得不通过删除我的项目,从源代码控制中获取旧版本,并将所有内容都恢复到正确的版本。一切恢复正常,我有一个最后一个问题。 Razor Syntax。



当我在项目的任何地方打开任何我的意见时,我得到:
< img src =https://i.stack.imgur.com/pX4S4.jpgalt =enter image description here>



注意使用Razor的内容是标有红色错误波纹。他们每个都会说当前上下文中不存在该名称



当我关闭文件时,不会显示任何错误。此外,当我运行项目时,没有任何问题,一切都可以完美。问题是,我没有智慧,它不认识我的剃刀助手。



以下是我项目的规格:

  EntityFramework 6.0 
Microsoft.Owin 2.1.0.0
Owin 1.0.0
System.Web.Mvc 5.2.2.0
System.Web.Razor 3.0.0.0

在我的包文件夹中我也有:

  Microsoft.AspNet.Mvc.5.2.2 
Microsoft.AspNet.Razor.3.2.2
Microsoft.WebPages.3.2.2

我修改了我的WebConfig来修复多个错误,现在它有以下代码:

 < compilation debug =truetargetFramework =4.5.1> 
< assembly>
< add assembly =System.Web.Abstractions,Version = 4.0.0.0,Culture = neutral,PublicKeyToken = 31BF3856AD364E35/>
< add assembly =System.Web.Helpers,Version = 3.0.0.0,Culture = neutral,PublicKeyToken = 31BF3856AD364E35/>
< add assembly =System.Web.Razor,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.Mvc,Version = 5.2.2.0,Culture = neutral,PublicKeyToken = 31BF3856AD364E35/>
< add assembly =System.Web.WebPages,Version = 3.0.0.0,Culture = neutral,PublicKeyToken = 31BF3856AD364E35/>
< / assemblies>
< / compilation>

和下:< runtime>< assemblyBinding xmlns =urn: schemas-microsoft-com:asm.v1>



我有这些:

 < dependentAssembly> 
< assemblyIdentity name =WebGreasepublicKeyToken =31bf3856ad364e35/>
< bindingRedirect oldVersion =0.0.0.0-1.5.2.14234newVersion =1.5.2.14234/>
< / dependentAssembly>
< dependentAssembly>
< assemblyIdentity name =Microsoft.AspNet.Identity.CorepublicKeyToken =31bf3856ad364e35culture =neutral/>
< bindingRedirect oldVersion =0.0.0.0-2.0.0.0newVersion =2.0.0.0/>
< / dependentAssembly>
< dependentAssembly>
< assemblyIdentity name =Newtonsoft.JsonpublicKeyToken =30ad4fe6b2a6aeedculture =neutral/>
< bindingRedirect oldVersion =0.0.0.0-4.5.0.0newVersion =4.5.0.0/>
< / dependentAssembly>
< dependentAssembly>
< assemblyIdentity name =Microsoft.Owin.Security.OAuthpublicKeyToken =31bf3856ad364e35culture =neutral/>
< bindingRedirect oldVersion =0.0.0.0-2.1.0.0newVersion =2.1.0.0/>
< / dependentAssembly>
< dependentAssembly>
< assemblyIdentity name =Microsoft.OwinpublicKeyToken =31bf3856ad364e35culture =neutral/>
< bindingRedirect oldVersion =0.0.0.0-2.1.0.0newVersion =2.1.0.0/>
< / dependentAssembly>
< dependentAssembly>
< assemblyIdentity name =Microsoft.Owin.SecuritypublicKeyToken =31bf3856ad364e35culture =neutral/>
< bindingRedirect oldVersion =0.0.0.0-2.1.0.0newVersion =2.1.0.0/>
< / dependentAssembly>
< dependentAssembly>
< assemblyIdentity name =Microsoft.Owin.Security.CookiespublicKeyToken =31bf3856ad364e35culture =neutral/>
< bindingRedirect oldVersion =0.0.0.0-2.1.0.0newVersion =2.1.0.0/>
< / dependentAssembly>
< dependentAssembly>
< assemblyIdentity name =Microsoft.WindowsAzure.StoragepublicKeyToken =31bf3856ad364e35culture =neutral/>
< bindingRedirect oldVersion =0.0.0.0-4.2.1.0newVersion =3.0.3.0/>
< / dependentAssembly>
< dependentAssembly>
< assemblyIdentity name =System.Web.HelperspublicKeyToken =31bf3856ad364e35/>
< bindingRedirect oldVersion =1.0.0.0-3.0.0.0newVersion =3.0.0.0/>
< / dependentAssembly>
< dependentAssembly>
< assemblyIdentity name =System.Web.RazorpublicKeyToken =31bf3856ad364e35/>
< bindingRedirect oldVersion =1.0.0.0-3.0.0.0newVersion =3.0.0.0/>
< / dependentAssembly>
< dependentAssembly>
< assemblyIdentity name =System.Web.WebPagespublicKeyToken =31bf3856ad364e35/>
< bindingRedirect oldVersion =0.0.0.0-3.0.0.0newVersion =3.0.0.0/>
< / dependentAssembly>
< dependentAssembly>
< assemblyIdentity name =System.Web.MvcpublicKeyToken =31bf3856ad364e35/>
< bindingRedirect oldVersion =0.0.0.0-5.2.2.0newVersion =5.2.2.0/>
< / dependentAssembly>

在我的项目中的每个查看文件夹中,我有以下 Web.Config 文件中的代码:

 < configSections> 
< sectionGroup name =system.web.webPages.razortype =System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup,System.Web.WebPages.Razor,Version = 3.0.0.0,Culture = neutral ,PublicKeyToken = 31BF3856AD364E35>
< section name =hosttype =System.Web.WebPages.Razor.Configuration.HostSection,System.Web.WebPages.Razor,Version = 3.0.0.0,Culture = neutral,PublicKeyToken = 31BF3856AD364E35requirePermission =false/>
< section name =pagestype =System.Web.WebPages.Razor.Configuration.RazorPagesSection,System.Web.WebPages.Razor,Version = 3.0.0.0,Culture = neutral,PublicKeyToken = 31BF3856AD364E35requirePermission =false/>
< / sectionGroup>
< / configSections>

随着这段代码:

 < system.web.webPages.razor> 
< host factoryType =System.Web.Mvc.MvcWebRazorHostFactory,System.Web.Mvc,Version = 5.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/>
< add namespace =IcapOrg/>
< / namespaces>
< / pages>
< /system.web.webPages.razor>

我已经尝试卸载它,重新安装,升级,降级,删除和添加程序集,以及许多更多的事情我已经开始忘记了。我不太确定从哪里移动。我可以继续编码,但只会在没有智慧感的情况下真正的痛苦。感谢您提前获得任何帮助。

解决方案

经过几天的搜索,我终于找到了这个页面: MVC Razor视图在VS 2013/2015/2017中打破了Intellisense



在我的视图> Web.Config 文件中,我发现这段代码:

 < 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.Routing/>
< add namespace =System.Web.Optimization/>
< add namespace =System.Web.Helpers/>
< add namespace =IcapOrg/>
< / namespaces>
< / pages>
< /system.web.webPages.razor>

您可以看到,哪个版本的MVC版本错误。我以前只检查 RAZOR 的正确版本的< sectionGroup> 标签,但我忽略了 MVC 也需要正确的版本。将版本切换到:

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

解决了我的问题。这让我想起来总是看看我的代码



注意:您可以在问题中看到,版本说5.0.0,而这一个说4.0.0。不同的Web.Config文件在不同的视图文件夹中都有不同的版本。非常奇怪


I was going through the list of NuGet Packages and I was updating everything things like bootstrap, jQuery, etc. but while I was doing that, I unthinkingly updated Microsoft.Owin and another package (might have been EF or something else) and it was a major version update...woops.

I had to jump through hoops by deleting my project, getting an older version from source control and getting everything back to the right versions. Everything is back to normal and I have one last issue. Razor Syntax.

When I open up any of my views...anywhere in the project, I get this:

Notice how anything using Razor is marked with red error squiggle. They each say "The name '' does not exist in the current context".

When I close the file, no errors are shown. Also, when I run the project, there are no issues and everything works PERFECT. The problem is, I have no intellisense and it doesn't recognize any of my razor helpers.

Here are the specifications for my project:

EntityFramework 6.0
Microsoft.Owin 2.1.0.0
Owin 1.0.0
System.Web.Mvc 5.2.2.0
System.Web.Razor 3.0.0.0

In my packages folder I also have:

Microsoft.AspNet.Mvc.5.2.2
Microsoft.AspNet.Razor.3.2.2
Microsoft.WebPages.3.2.2

I've modified my WebConfig to fix multiple errors and it now has the following code in it:

<compilation debug="true" targetFramework="4.5.1">
      <assemblies>
        <add assembly="System.Web.Abstractions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
        <add assembly="System.Web.Helpers, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
        <add assembly="System.Web.Razor, 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.Mvc, Version=5.2.2.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
        <add assembly="System.Web.WebPages, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
      </assemblies>
    </compilation>

and under: <runtime><assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">

I have these:

<dependentAssembly>
        <assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="0.0.0.0-1.5.2.14234" newVersion="1.5.2.14234" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.AspNet.Identity.Core" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-4.5.0.0" newVersion="4.5.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.Owin.Security.OAuth" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-2.1.0.0" newVersion="2.1.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.Owin" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-2.1.0.0" newVersion="2.1.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.Owin.Security" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-2.1.0.0" newVersion="2.1.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.Owin.Security.Cookies" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-2.1.0.0" newVersion="2.1.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.WindowsAzure.Storage" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-4.2.1.0" newVersion="3.0.3.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Razor" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="0.0.0.0-5.2.2.0" newVersion="5.2.2.0" />
      </dependentAssembly>

And on each of the View folders in my project I have the following code inside of the 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>

Along with this code:

    <system.web.webPages.razor>
    <host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=5.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" />
        <add namespace="IcapOrg" />
      </namespaces>
    </pages>
  </system.web.webPages.razor>

I have tried uninstalling it, re-installing, upgrading, downgrading, removing and adding assemblies, and many more things I've started to forget. I'm not really sure where to move on from here. I can keep coding but it's just going to be a real pain without intellisense. Thank you in advance for any help.

解决方案

After days of searching, I finally found this page: MVC Razor view Intellisense broken in VS 2013/2015/2017

In my Views > Web.Config file I found this code:

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

Which, as you can see, has the wrong version of MVC on it. I had previously only checking the <sectionGroup> tags for the proper version of RAZOR but I neglected the fact that MVC also needs the proper version. Switching the version to:

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

Solved my problem. This reminds me to always look over my code VERY carefully.

NOTE: As you can see in the question, the version says 5.0.0, and this one says 4.0.0. Different Web.Config files in my different view folders all had different versions written down. Extremely weird.

这篇关于Razor语法在编译之前在View中给出错误(无智能感知)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆