c# - 与 Nancy 一起使用 Razor 进行智能感知

标签 c# .net razor nancy

我开始了一个新的Nancy使用 Visual Studio 2013 的 .Net 4.5.1 中的项目。 我使用 Razor 作为 View 引擎。 一切都构建并工作,但我想要智能感知而不使用完整的命名空间。 这可能吗?

这是我的 web.config:

<configuration>
  <configSections>
    <section name="razor" type="Nancy.ViewEngines.Razor.RazorConfigurationSection, Nancy.ViewEngines.Razor" />
    <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="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false"/>
    </sectionGroup>
  </configSections>

  <razor disableAutoIncludeModelNamespace="false">
    <assemblies>
      <add assembly="IC.Resources" />
    </assemblies>
    <namespaces>
      <add namespace="IC.Web.Client.Models" />
      <add namespace="IC.Resources" />
    </namespaces>
  </razor>

  <system.web.webPages.razor>
    <pages pageBaseType="Nancy.ViewEngines.Razor.NancyRazorViewBase">
      <namespaces>
        <add namespace="Nancy.ViewEngines.Razor"/>
        <add namespace="IC.Web.Client.Models" />
        <add namespace="IC.Resources" />
      </namespaces>
    </pages>
  </system.web.webPages.razor>
</configuration>

如果我使用 IC.Resources 或 IC.Web.Client.Models 中的代码,我仍然需要使用完整的命名空间。

这是我的观点的顶部:

@inherits Nancy.ViewEngines.Razor.NancyRazorViewBase<IC.Web.Client.Models.LoginModel>

如果我将其添加到每个页面的顶部,它就会起作用:

@using IC.Resources;
@using IC.Web.Client.Models

但我不喜欢在每一页上重复这一点。 我尝试仅将 using 添加到布局页面,但这不起作用。

@{ Layout = "_layout.cshtml"; }

最佳答案

如果将 System.Object 定义添加到 pageBaseType 中,则无需添加两个 using 语句。

<system.web.webPages.razor>
    <pages pageBaseType="Nancy.ViewEngines.Razor.NancyRazorViewBase`1[[System.Object]]">
        <namespaces>
            <add namespace="Nancy.ViewEngines.Razor" />
        </namespaces>
    </pages>
</system.web.webPages.razor>

关于c# - 与 Nancy 一起使用 Razor 进行智能感知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21808226/

相关文章:

C# Linq/Lambda 表达式 : How to select an integer out of a string?

c# - 如何在 Xamarin Android 中设置 SQLite(SQLite.NET 组件)数据库版本

c# - Html.Action 抛出 "asynchronous operation"InvalidOperationException

c# - asp.net.mvc中@*运算符是什么意思?

javascript - 在 javascript 中使用空 c# 模型

c# - 处理键盘输入的最佳方式 "wedge"

c# - 将枚举序列化为字符串时,是否可以添加新的枚举成员而不破坏与 Newtonsoft json 的契约(Contract)?

c# - Visual Studio 2010 不断改变我的 winforms 控件

c# - OpenFileDialog 多选问题

.net - 如何正确记录扩展方法