在视图 web.config 中添加了名称空间,但视图 cshtml 上没有可用的智能感知

NameSpaces added in view web.config but no intellisence is available on view cshtml

我在 Sitecore 8.1 中使用带有玻璃映射器的 MVC 5,但这个问题似乎对于所有 MVC 版本都是一样的。

我必须在我的每个视图中使用很多引用,所以我决定在 View/web.config 中移动它们,如下所示

<system.web.webPages.razor>
    <host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=5.2.3.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" />

        <!-- Glass Mapper Namespaces -->
        <add namespace="Glass.Mapper.Sc.Mvc" />
        <add namespace="Glass.Mapper.Sc" />
        <add namespace="Glass.Mapper" />
        <add namespace="Glass.Mapper.Sc.Web.Mvc" />

        <!-- Sitecore Namespaces-->
        <add namespace="Sitecore" />
        <add namespace="Sitecore.Mvc"/>
        <add namespace="Sitecore.Mvc.Presentation" />
        <!--<add namespace="Sitecore.Mvc.Analytics"/>-->
        <add namespace="Sitecore.Mvc.Analytics.Extensions"/>

        <!-- xxx Namespaces-->
        <add namespace="xxx.SC.GlassMapper.ViewModel.Layout.Layouts.Renderings.Components.Global.Navigation"/>
        <add namespace="xxx.SC.GlassMapper.ViewModel.Layout.Layouts.Renderings.Components.Global.Site"/>
        <add namespace="xxx.SC.GlassMapper.ViewModel.Layout.Layouts"/>
        <add namespace="xxx.SC.GlassMapper.Model.Pages"/>
        <add namespace="xxx.SC.Shared.References"/>

      </namespaces>
    </pages>
  </system.web.webPages.razor>

如果我通过 @using 属性在视图本身上引用它们,它工作正常,但现在我将引用移动到 view/web.config 文件后它不起作用。

视图如下:

@inherits GlassView<Main>

@{
    Layout = null;
}

<!DOCTYPE html>
<html>
<head lang="@Model.LanguageIsoCode">

    @Html.Sitecore().Rendering(LayoutIDs.Head, Model.HeadDataSource)
    @Html.Sitecore().Rendering(LayoutIDs.StyleSheets)

</head>
<body lang="@Model.LanguageIsoCode">
    @Html.Sitecore().Rendering(LayoutIDs.Header, Model.MainNavigationDataSource)

    @Html.Sitecore().Placeholder("PlaceholderMain")

    @Html.Sitecore().Rendering(LayoutIDs.Footer, Model.FooterDataSource)
    @Html.Sitecore().Rendering(LayoutIDs.Scripts)
</body>

</html>

前几天我写了一篇关于此的博客 post。感谢 Jammy Kam。

您需要做的就是在 Visual Studio 中将每个 Sitecore dll 设置为 CopyLocal = true。

http://www.waitingimpatiently.com/intellisense-issue-when-using-sitecore-local-nuget-files/