避免使用CamelCasePropertyNamesContractResolver的特定方法 [英] Avoiding CamelCasePropertyNamesContractResolver for a specific method

查看:1577
本文介绍了避免使用CamelCasePropertyNamesContractResolver的特定方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有Web api控制器,并且正在WebApiConfig文件中使用这种配置方法来对所有控制器的结果进行驼峰式封装.

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();

现在我有一个控制器的方法,该方法将数据提供给Angularjs翻译提供程序,并且所有翻译字符串都不在我的html中的驼峰格式中,这就是为什么我需要该方法的结果不在CamelCase中的原因.如何避免使用此特定控制器方法的骆驼肠衣序列化行为.

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.

推荐答案

您可以使用只需从您的控制器方法中返回即可

just return like this from your controller method

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

这篇关于避免使用CamelCasePropertyNamesContractResolver的特定方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆