C# NancyFx在Razor视图引擎中找不到NewtonSoft引用
我有一个简单的部分:C# NancyFx在Razor视图引擎中找不到NewtonSoft引用,c#,asp.net-mvc,razor,json.net,nancy,C#,Asp.net Mvc,Razor,Json.net,Nancy,我有一个简单的部分: <div class="col-xs-12"> <label>view model</label> <textarea class="form-control btn-xs" rows="12">@JsonConvert.SerializeObject(Model)</textarea> </div> 在部分或主要cshtml中,或: <system.web.webPages.r
<div class="col-xs-12">
<label>view model</label>
<textarea class="form-control btn-xs" rows="12">@JsonConvert.SerializeObject(Model)</textarea>
</div>
在部分或主要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>
或
愚蠢的问题:您是否已将Json.NETNuget包添加到您的项目中
最后一次尝试失败的最简单解释就是 我必须将以下内容添加到我的Web.config中以消除此错误
<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>
你真的安装了Newtonsoft软件包吗?我在谷歌上搜索了一下,好像有专门为nancy设计的软件包。这应该是你的问题。看看这里,我已经安装了软件包,它可以在视图之外的项目中工作。是的,我已经安装了正确的软件包。在视图之外,对Newtonsoft.Json的引用可以正常工作。
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
<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>