Skip to content
This repository was archived by the owner on Dec 14, 2018. It is now read-only.
This repository was archived by the owner on Dec 14, 2018. It is now read-only.

ModelState does not adhere to DataMember Name or DisplayName #6942

@carl-thomas

Description

@carl-thomas

When posting JSON data

{
    "name": "Dave",
    "email_address": "dave@dave.com"
}

to a endpoint that accepts the relevant model...

[DataContract]
public class MyModel 
{
    [DataMember(Name = "name")]
    [Required]
    public string Name { get; set; }

    [DataMember(Name = "email_address")]
    [Required]
    [EmailAddress]
    public string EmailAddress { get; set; }
}

When this model gets validated, if the validation failed and you return BadRequest(ModelState) you get the response e.g.

{
    "Name": [
        "The Name field is required."
    ],
    "EmailAddress": [
        "The EmailAddress field is not a valid e-mail address."
    ]
}

The keys are the property names e.g. EmailAddress and not the original DataMember name email_address

The response should adhere to the DataMember attribute so that the response resembles the external keys the user sees.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions