简体   繁体   English

Razor heper方法无法识别

[英]Razor heper methods not recognized

Ever since I upgraded my project to MVC4, my Razor helpers are marked with red squiggles, and intellisense doesn't work; 自从我将项目升级到MVC4后,我的Razor助手都标有红色曲线,智能感应不起作用; everything works at design time though. 一切都在设计时工作。 Can anyone help? 有人可以帮忙吗?

在此输入图像描述

Here is what my Views/Web.config has. 这是我的Views / 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="Qwiple.Web.Views.BaseViewPage">
    <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.Helpers"/>
    </namespaces>
  </pages>
</system.web.webPages.razor>

In my case, the following line was missing from the razor section in the Views/web.config, under namespaces: 就我而言,名称空间下的Views / web.config中的剃刀部分缺少以下行:

<add namespace="System.Web.Helpers"/>

Note that this line is present in Joe's original example above, so we're not all having the same problem. 请注意,这一行出现在上面Joe的原始示例中,因此我们并非都有同样的问题。

I figured it out. 我想到了。 During the upgrade I missed changing the version of the razor section in the Views/web.config. 在升级过程中,我错过了在Views / web.config中更改剃刀部分的版本。 Make sure that the section groups match the sample below. 确保部分组与下面的示例匹配。

<sectionGroup name="system.web.webPages.razor" type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
  <section name="host" type="System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
  <section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
</sectionGroup>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM