我只想使用适用于WEB API的条件必填属性。
示例。
示例。
public sealed class EmployeeModel
{
[Required]
public int CategoryId{ get; set; }
public string Email{ get; set; } // If CategoryId == 1 then it is required
}
我正在使用通过 (ActionFilterAttribute) 的模型状态验证。
[RequiredIf("CategoryId == 1")]
。请注意,此翻译中保持了原文的意思和表达方式,并尽力使其通俗易懂。 - jwaliszko