Permalink
Browse files

Project was missing the controller file.

  • Loading branch information...
1 parent 561c831 commit 5626075910fbc2a44e54399e22501296621af98f @patridge committed Jul 5, 2012
Showing with 59 additions and 3 deletions.
  1. +2 −3 JsonNetIHtmlStringTesting/JsonNetIHtmlStringTesting.csproj
  2. +57 −0 README.markdown
@@ -44,6 +44,7 @@
<Reference Include="System.Configuration" />
</ItemGroup>
<ItemGroup>
+ <Compile Include="Controllers\JsonSerializationController.cs" />
<Compile Include="Global.asax.cs">
<DependentUpon>Global.asax</DependentUpon>
</Compile>
@@ -62,9 +63,7 @@
<DependentUpon>Web.config</DependentUpon>
</Content>
</ItemGroup>
- <ItemGroup>
- <Folder Include="Controllers\" />
- </ItemGroup>
+ <ItemGroup />
<ItemGroup>
<Content Include="packages.config" />
</ItemGroup>
View
@@ -0,0 +1,57 @@
+##Default .NET JavaScript serialization
+
+ // Controller action method
+ public JsonResult Default() {
+ return Json(new {
+ String = test,
+ IHtmlString = MvcHtmlString.Create(test),
+ }, JsonRequestBehavior.AllowGet);
+ }
+
+ // JSON output
+ {
+ "String": "some <span>test</span>.",
+ "IHtmlString": {}
+ }
+
+##Default Json.NET serialization
+
+ // Controller action method
+ public StandardJsonNetJsonResult StandardJsonNet() {
+ return new StandardJsonNetJsonResult(new {
+ String = test,
+ IHtmlString = MvcHtmlString.Create(test),
+ }, JsonRequestBehavior.AllowGet);
+ }
+
+ // JSON output
+ {
+ "String": "some <span>test</span>.",
+ "IHtmlString": {}
+ }
+
+##Custom Json.NET serialization (with IHtmlStringConverter)
+
+ // Custom JsonConverter method
+ public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) {
+ IHtmlString source = value as IHtmlString;
+ if (source == null) {
+ return;
+ }
+
+ writer.WriteValue(source.ToString());
+ }
+
+ // Controller action method
+ public CustomJsonNetJsonResult CustomJsonNet() {
+ return new CustomJsonNetJsonResult(new {
+ String = test,
+ IHtmlString = MvcHtmlString.Create(test),
+ }, JsonRequestBehavior.AllowGet);
+ }
+
+ // JSON output
+ {
+ "String": "some <span>test</span>.",
+ "IHtmlString": "some <span>test</span>."
+ }

0 comments on commit 5626075

Please sign in to comment.