Avoiding CamelCasePropertyNamesContractResolver for a specific method

六眼飞鱼酱① 提交于 2019-12-07 04:26:27

问题


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.


回答1:


you can use ApiController.Json method.

just return like this from your controller method

return Json(data, new JsonSerializerSettings { ContractResolver = new DefaultContractResolver() });


来源:https://stackoverflow.com/questions/28767660/avoiding-camelcasepropertynamescontractresolver-for-a-specific-method

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!