У меня есть простой частичный:
<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>
в Views/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
Мне пришлось добавить следующее к моему 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>
Глупый вопрос: добавили ли вы пакет Json.Net nuget в свой проект?
Простейшим объяснением последней попытки, не работающей, было бы просто так.