NancyFx无法在Razor视图引擎中找到NewtonSoft引用

本文关键字:NewtonSoft 引用 引擎 视图 Razor NancyFx | 更新日期: 2023-09-27 18:04:26

我有一个简单的部分:

<div class="col-xs-12">
    <label>view model</label>
    <textarea class="form-control btn-xs" rows="12">@JsonConvert.SerializeObject(Model)</textarea>
</div>

:

@using Newtonsoft.Json

在部分或主cshtml中,而不是:

<system.web.webPages.razor>
    <host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
    <pages pageBaseType="System.Web.Mvc.WebViewPage">
        <namespaces>
            <add namespace="Newtonsoft.Json" />
        </namespaces>
    </pages>
</system.web.webPages.razor>

在视图/web . config。我仍然得到:

The type or namespace name 'Newtonsoft' could not be found (are you missing a using directive or an assembly reference?)

The name 'JsonConvert' does not exist in the current context

NancyFx无法在Razor视图引擎中找到NewtonSoft引用

我必须将以下内容添加到我的Web中。配置以消除此错误

<configuration>
  <configSections>
    <section name="razor" type="Nancy.ViewEngines.Razor.RazorConfigurationSection, Nancy.ViewEngines.Razor" />
  </configSections>
  <razor disableAutoIncludeModelNamespace="false">
    <assemblies>
      <add assembly="Newtonsoft.Json" />
    </assemblies>
    <namespaces>
      <add namespace="Newtonsoft.Json" />
    </namespaces>
  </razor>
</configuration>

愚蠢的问题:你添加Json了吗?Net nuget包到您的项目?

最后一次尝试失败的最简单的解释就是。