6

I have web api controllers and I am using this method of configuration in WebApiConfig file for camel casing my results for all controllers.

var json = GlobalConfiguration.Configuration.Formatters.JsonFormatter;
json.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();

Now I have a controller's method which is giving data to Angularjs translation provider and all translation strings are not in camelcase in my html, thats why I need results of that method to be not in CamelCase. How to avoid camel casing serialization behavior for this specific controllers' method.

Hamid Pourjam
  • 20,441
  • 9
  • 58
  • 74
ahmadalibaloch
  • 5,851
  • 2
  • 50
  • 59
  • 1
    This works good for me http://stackoverflow.com/questions/19956838/force-camalcase-on-asp-net-webapi-per-controller – Nirmal Dec 17 '15 at 09:05

1 Answers1

9

you can use ApiController.Json method.

just return like this from your controller method

return Json(data, new JsonSerializerSettings { ContractResolver = new DefaultContractResolver() });
Hamid Pourjam
  • 20,441
  • 9
  • 58
  • 74