Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

Deserializing a complex type in WebAPI is giving me serious grief. The data contains keys that are syntactically invalid in c# as property names. How can I translate the key names?

Relevant: Web API form-urlencoded binding to different property names

share|improve this question
add comment

1 Answer

You can use JSON.NET's JsonProperty to do the trick:

public class SomeModel {
    [JsonProperty("YourCustomName")]
    public string SomeProperty { get; set; }
}
share|improve this answer
    
FormUrlEncodedMediaTypeFormatter will recognize that attribute? –  Ablue Jun 25 at 5:26
    
Looks like for the purposes of JSON deserialization and serialization it works but not for form urlencoded data. –  Ablue Jun 25 at 6:13
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.