我该如何在.NET框架的WEB Api中将modelstate键设为驼峰命名法:
我使用JsonProperty属性来设置属性名称为驼峰命名法。现在我希望modelstate与json相同(都是驼峰命名法),我该怎么做呢?
我该如何在.NET框架的WEB Api中将modelstate键设为驼峰命名法:
我使用JsonProperty属性来设置属性名称为驼峰命名法。现在我希望modelstate与json相同(都是驼峰命名法),我该怎么做呢?
.AddJsonOptions(options =>
{
options.SerializerSettings.ContractResolver = new DefaultContractResolver
{
NamingStrategy = new CamelCaseNamingStrategy
{
ProcessDictionaryKeys = true
}
};
});
ConfigureServices()
中,替换ContractResolver
:public void ConfigureServices(IServiceCollection services) {
services.AddMvc()
.AddJsonOptions(options => options.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver());
}