Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You need to create a custom validation attribute - there's is plenty of help on the web. The following is an adaptation from a similar dependant attribute.</p> <pre><code>public class GreaterThanOtherAttribute : ValidationAttribute, IClientValidatable { public string DependentProperty { get; set; } public GreaterThanOtherAttribute (string dependentProperty) { this.DependentProperty = dependentProperty; } protected override ValidationResult IsValid(object value, ValidationContext validationContext) { // get a reference to the property this validation depends upon var containerType = validationContext.ObjectInstance.GetType(); var field = containerType.GetProperty(this.DependentProperty); if (field != null) { // get the value of the dependent property var dependentvalue = field.GetValue(validationContext.ObjectInstance, null); // compare the value against the target value if ((dependentvalue == null &amp;&amp; this.TargetValue == null) || (dependentvalue != null &amp;&amp; dependentvalue &lt; this.TargetValue))) { // match =&gt; means we should try validating this field return new ValidationResult(this.ErrorMessage, new[] { validationContext.MemberName }); } } return ValidationResult.Success; } </code></pre> <p>and then decorate your model:</p> <pre><code>public class id { [Required] public decimal l_ID { get; set; } [Required] [GreaterThanOtherAttribute("l_ID")] public decimal v_ID { get; set; } } </code></pre> <p>What you now need to do is to find an example custom attribute and adapt it to use the above.</p> <p>HEALTH WARNING - this is not tested in any way and probably contains error.</p> <p>Good luck!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload