我有一个具有三个属性的模型。我想向TotalSalary
添加验证逻辑,其中TotalSalary
必须等于BasicSalary
和AllowanceSalary
的总和。
public class Employee
{
[Required]
public decimal BasicSalary{get;set;}
[Required]
public decimal AllowanceSalary{get;set;}
[MyCompareAttribute]
public decimal TotalSalary{get;set;}
}
public class MyCompareAttribute: ValidationAttribute
{
// I have no idea how to do this
}