In my CS file, I am doing the following and working as expected.
using System.Web.Helpers;
String json = System.Web.Helpers.Json.Encode(null);
However, in my CSHTML file, I do the following, and here I get an error when Json is not recognized in context.
@{ Layout = null; }
@using TestService.ServiceReference;
@using System.Web.Helpers;
<!DOCTYPE html>
<html>
...
<script type="text/javascript">
var output3 = "! @Html.Raw(Json.Encode(ViewBag.MyArray))";
...
How can this be explained / corrected? Googling gave me nada, zero, ziltch ...
Edit
I added the assembly tag to my CONFIG file, as suggested, but the error I get is that it is unknown to the configuration. This is what my (root) CONFIG looks like.
<system.web>
<compilation debug="true" targetFramework="4.0" />
<assemblies>
<add assembly="System.Web.Helpers, Version=2.0.0.0,
Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
</assemblies>
...
However, I noticed that instead I have the following in the CONFIG file. I guess this is equivalent. It?
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
source
share