title: Range attribute using dynamic values instead of fixed
body: <p>I want to use Data annotations Range attribute inside my mvc viewmodel. Problem is that this range attributes should be dynamic values.</p>
  
  <p>My viewmodel has also ValueOne and ValueTwo properties. Based on this values I want to set Range attr. values like </p>
  
  <pre><code> [Range(1, 1000, ErrorMessage = "Value for {0} must be between {1} and {2}.")]
  </code></pre>
  
  <p>Where 1 and 1000 should be replaces with ValueOne and ValueTwo property values.</p>
  
  <p>so I tried with custom ValidateCustomAttribute</p>
  
  <pre><code>public class ValidateCustomAttribute: ValidationAttribute
      {
          private readonly double _MinValue = 0;
          private readonly double _MaxValue = 100;
  
          public override bool IsValid(object value)
          {
              double val = (double)value;
              return val &gt;= _MinValue &amp;&amp; val &lt;= _MaxValue;
          }
  
          public override string FormatErrorMessage(string name)
          {
              return string.Format(ErrorMessage, _MinValue, _MaxValue);
          }
      }
  </code></pre>
  
  <p>how can I replace this </p>
  
  <pre><code>private readonly double _MinValue = 0;
  private readonly double _MaxValue = 100;
  </code></pre>
  
  <p>with dynamic values (ValueOne and ValueTwo from my viewmodel).</p>