I am receiving the following VM on a Web API Post action
public class ViewModel
{
public string Name { get; set; }
[Required]
public int? Street { get; set; }
}
When I make a post I get the following error:
Property 'Street' on type 'ViewModel' is invalid. Value-typed properties marked as [Required] must also be marked with [DataMember(IsRequired=true)] to be recognized as required. Consider attributing the declaring type with [DataContract] and the property with [DataMember(IsRequired=true)].
It seems the error is clear so I just want to be completely sure that it is required to use [DataContract] and [DataMember] attributes when you have a class with required nullable properties.
Is there a way to avoid using these attributes in Web API?