According to the docs,IgnoreDataMember属性只应在序列化期间考虑。IgnoreDataMember属性在** DE **序列化期间跳过json对象属性
从我所看到的,但是,MVC模型绑定使用* de * json序列化以及。
考虑下面的类:
public class Tax
{
public Tax() { }
public int ID { get; set; }
[Required]
[Range(1, int.MaxValue)]
[IgnoreDataMember]
public int PropertyId { get; set; }
}
如果POST/PUT以下JSON字符串的操作方法:
{"Position":0,"Description":"State sales tax","Rate":5,"RateIsPercent":true,"PropertyId":1912}
我得到以下验证错误:
{
"Message": "The request is invalid.",
"ModelState": {
"newTax.PropertyId": [
"The field PropertyId must be between 1 and 2147483647."
]
}
}
[Range(1, int.MaxValue)]
和[Required]
属性均无效。
如果我删除[IgnoreDataMember]
属性,一切工作正常。
是否有不同的属性,可以使用它会告诉MVC绑定不要忽略反序列化过程中的属性?
这只发生在发布json字符串时。如果我发布名称/值字符串,everthing可以正常工作。