How do I set the modelstate keys to camel case in WEB Api .net framework.
I use JsonProperty attribute to set the property names to camel case. Now I want the modelstate to be the same as the json (camel case) how do I achieve that?
You can do it as follows:
.AddJsonOptions(options =>
{
options.SerializerSettings.ContractResolver = new DefaultContractResolver
{
NamingStrategy = new CamelCaseNamingStrategy
{
ProcessDictionaryKeys = true
}
};
});
When configuring MVC in your ConfigureServices()
, replace the ContractResolver
:
public void ConfigureServices(IServiceCollection services) {
services.AddMvc()
.AddJsonOptions(options => options.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver());
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With