Created
January 1, 2015 09:19
-
-
Save wcadap/e4c11699f6281100711e to your computer and use it in GitHub Desktop.
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
using Newtonsoft.Json; | |
using Newtonsoft.Json.Serialization; | |
using System; | |
using System.Net; | |
using System.Web.Mvc; | |
namespace Contacts.Helpers | |
{ | |
public class JsonController : Controller | |
{ | |
// | |
// GET: /Json/ | |
public new ActionResult Json(object data, JsonRequestBehavior behavior) | |
{ | |
var jsonSerializerSetting = new JsonSerializerSettings | |
{ | |
ContractResolver = new CamelCasePropertyNamesContractResolver() | |
}; | |
if (Request.RequestType == WebRequestMethods.Http.Get && behavior == JsonRequestBehavior.DenyGet) | |
{ | |
throw new InvalidOperationException("GET is not permitted for this request."); | |
} | |
var jsonResult = new ContentResult | |
{ | |
Content = JsonConvert.SerializeObject(data, jsonSerializerSetting), | |
ContentType = "application/json" | |
}; | |
return jsonResult; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment