How to tell JSON.NET StringEnumConverter to take DisplayName?

前端 未结 3 1946
死守一世寂寞
死守一世寂寞 2021-02-02 12:31

I\'ve got the following model:

public enum Status
{
    [Display(Name = \"Awaiting Approval\")]
    AwaitingApproval,
    Rejected,
    Accepted,
}
3条回答
  •  你的背包
    2021-02-02 13:00

    You should try using [EnumMember] instead of [Display]. You can also put the [JsonConverter] attribute on the enum itself.

    [JsonConverter(typeof(StringEnumConverter))]
    public enum Status
    {
        [EnumMember(Value = "Awaiting Approval")]
        AwaitingApproval,
        Rejected,
        Accepted,
    }
    

    The VB.NET version for the JsonConverter attribute is:

    
    

提交回复
热议问题