I was hoping to be able to do something like this:
public class MinimumSalaryAttribute : ValidationAttribute
{
private readonly decimal _minValue;
public MinimumSalaryAttribute(decimal minValue)
{
_minValue = minValue;
}
public override bool IsValid(object value)
{
return (decimal)value > _minValue;
}
}
and then in my view:
[MinimumSalary(0M)]
public decimal Salary { get; set; }
This would prevent users entering negative decimals. However, I get a compiler error: "not a valid attribute type". I understand the reason for this as described here: Why "decimal" is not a valid attribute parameter type?
What is the workaround in my vase?