Created
April 22, 2013 11:40
-
-
Save rgripper/5434106 to your computer and use it in GitHub Desktop.
CamelCaseJonResult
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class CamelCaseJonResult : JsonResult | |
{ | |
public override void ExecuteResult(System.Web.Mvc.ControllerContext context) | |
{ | |
base.ExecuteResult(context); | |
} | |
public override void ExecuteResult(ControllerContext context) | |
{ | |
if (context == null) | |
{ | |
throw new ArgumentNullException("context"); | |
} | |
if (JsonRequestBehavior == JsonRequestBehavior.DenyGet && | |
String.Equals(context.HttpContext.Request.HttpMethod, "GET", StringComparison.OrdinalIgnoreCase)) | |
{ | |
throw new InvalidOperationException(); | |
} | |
System.Web.HttpResponseBase response = context.HttpContext.Response; | |
if (!String.IsNullOrEmpty(ContentType)) | |
{ | |
response.ContentType = ContentType; | |
} | |
else | |
{ | |
response.ContentType = "application/json"; | |
} | |
if (ContentEncoding != null) | |
{ | |
response.ContentEncoding = ContentEncoding; | |
} | |
if (Data != null) | |
{ | |
var result = Newtonsoft.Json.JsonConvert.SerializeObject( | |
Data, | |
Formatting.Indented, | |
new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver() }); | |
response.Write(result); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment