Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Avoiding CamelCasePropertyNamesContractResolver for a specific method

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.

like image 365
ahmadalibaloch Avatar asked Feb 27 '15 14:02

ahmadalibaloch


1 Answers

you can use ApiController.Json method.

just return like this from your controller method

return Json(data, new JsonSerializerSettings { ContractResolver = new DefaultContractResolver() });
like image 79
Hamid Pourjam Avatar answered Sep 19 '22 01:09

Hamid Pourjam