c# – 如何将Modelstate错误键设置为驼峰大小写?

如何在WEB Api .net框架中将modelstate键设置为camel case.

我使用JsonProperty属性将属性名称设置为camel case.
现在我希望模型状态与json(驼峰情况)相同,我该如何实现?

最佳答案 在ConfigureServices()中配置MVC时,替换ContractResolver:

public void ConfigureServices(IServiceCollection services) {
    services.AddMvc()
        .AddJsonOptions(options => options.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver());
}
点赞