Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Something along the lines of this might be more what your after...</p> <p>ViewModel:</p> <pre><code>public class ViewModel { public DateTime MinDate {get; set;} public DateTime MaxDate {get; set;} [DynamicRange("MinDate", "MaxDate", ErrorMessage = "Value must be between {0} and {1}")] public DateTime Date{ get; set; } } </code></pre> <p>Library class or elsewhere:</p> <pre><code>public class DynamicRange : ValidationAttribute, IClientValidatable { private readonly string _minPropertyName; private readonly string _maxPropertyName; public DynamicRange(string minPropName, string maxPropName) { _minPropertyName = minPropName; _maxPropertyName = maxPropName; } protected override ValidationResult IsValid(object value, ValidationContext validationContext) { var minProperty = validationContext.ObjectType.GetProperty(_minPropertyName); var maxProperty = validationContext.ObjectType.GetProperty(_maxPropertyName); if(minProperty == null) return new ValidationResult(string.Format("Unknown property {0}", _minPropertyName)); if (maxProperty == null) return new ValidationResult(string.Format("Unknown property {0}", _maxPropertyName)); var minValue = (int) minProperty.GetValue(validationContext.ObjectInstance, null); var maxValue = (int) maxProperty.GetValue(validationContext.ObjectInstance, null); var currentValue = (int) value; if (currentValue &lt;= minValue || currentValue &gt;= maxValue) { return new ValidationResult(string.Format(ErrorMessage, minValue, maxValue)); } return null; } public IEnumerable&lt;ModelClientValidationRule&gt; GetClientValidationRules(ModelMetadata metadata, ControllerContext context) { var rule = new ModelClientValidationRule { ValidationType = "dynamicrange", ErrorMessage = ErrorMessage }; rule.ValidationParameters["minvalueproperty"] = _minPropertyName; rule.ValidationParameters["maxvalueproperty"] = _maxPropertyName; yield return rule; } </code></pre> <p>From: <a href="https://stackoverflow.com/questions/7851035/mvc-unobtrusive-range-validation-of-dynamic-values">MVC unobtrusive range validation of dynamic values</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

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