【发布时间】:2016-06-17 07:46:43
【问题描述】:
我正在使用模型验证来验证 Web api 请求:
动作过滤器属性
是否有可能对模型的属性“B”有一个验证规则,它依赖于属性“A”。考虑这个例子以获得更多说明
public class ValidationModel
{
[Required]
public int? Id { get; set; }
public string Barcode { get; set; }
public string BarcodeType { get; set; }
}
上述模型有一个 Id 属性是必需的,而 Barcode,BarcodeType 属性是可选的,是否可以将 BarcodeType 属性设置为必需当且仅当 Barcode 属性中有任何值(如果它不为 null 并且一个空字符串)
【问题讨论】:
-
RequiredIf 数据注释可能就是您要搜索的内容..
标签: c# asp.net asp.net-web-api