验证响应属性名称是PascalCase而不是camelCase

时间:2017-04-29 17:30:27

标签: c# asp.net asp.net-web-api asp.net-core-webapi

我有这个简单的模型,其中PascalCase中的属性是C#中的默认约定:

public class ItemUpdateModel
{
    [Required]
    [Display(Name = "descriptionText")]
    [MaxLength(200)]
    public string DescriptionText { get; set; }

    [Required]
    [Display(Name = "priceUpdate")]
    public double? PriceUpdate { get; set; }
}

当我从ModelState返回结果时,我得到PascalCase中显示的属性/字段,如下所示:

{
  "message": "Validation Failed",
  "errors": [
    {
      "field": "PriceUpdate",
      "message": "The priceUpdate field is required."
    },
    {
      "field": "DescriptionText",
      "message": "The descriptionText field is required."
    }
  ]
}

我在startup.cs中添加了CamelCasePropertyNamesContractResolver()而没有结果。

0 个答案:

没有答案