title: Get value of a property that was passed in as a string
body: <p>I am trying to create a custom validation that says "if the otherValue is true, then this value must be greater than 0.  I am able to get the value in, but the way I currently have the otherValue set up, I only have the name of the property, not the value.  Probably because it passed in as a string.  This attribute is going to be on 5 or 6 different properties and each time, it will be calling a different otherValue.  Looking for help on how to get the actual value (it is a bool) of otherValue.</p>
  
  <p>Here is my current code:</p>
  
  <pre><code>public class MustBeGreaterIfTrueAttribute : ValidationAttribute, IClientValidatable
  {
      // get the radio button value
      public string OtherValue { get; set; }
  
      public override bool IsValid(object value)
      {
          // Here is the actual custom rule
          if (value.ToString() == "0")
          {
              if (OtherValue.ToString() == "true")
              {
                  return false;
              }
          }
          // If all is ok, return successful.
          return true;
      }
  </code></pre>
  
  <p>======================EDIT=========================</p>
  
  <p>Here is where I am at now, and it works!  Now I need a refernce on how to make it so I can put in a different errorMessage when adding the attribute in the model:</p>
  
  <pre><code>public class MustBeGreaterIfTrueAttribute : ValidationAttribute, IClientValidatable
  {
      // get the radio button value
      public string OtherProperty { get; set; }
  
      protected override ValidationResult IsValid(object value, ValidationContext context)
      {
          var otherPropertyInfo = context.ObjectInstance.GetType();
          var otherValue = otherPropertyInfo.GetProperty(OtherProperty).GetValue(context.ObjectInstance, null);      
  
          // Here is the actual custom rule
          if (value.ToString() == "0")
          {
              if (otherValue.ToString().Equals("True", StringComparison.InvariantCultureIgnoreCase))
              {
                  return new ValidationResult("Ensure all 'Yes' answers have additional data entered.");
              }
          }
          // If all is ok, return successful.
          return ValidationResult.Success;
      }
  
      // Add the client side unobtrusive 'data-val' attributes
      public IEnumerable&lt;ModelClientValidationRule&gt; GetClientValidationRules(ModelMetadata metadata, ControllerContext context)
      {
          var rule = new ModelClientValidationRule();
          rule.ValidationType = "requiredifyes";
          rule.ErrorMessage = this.ErrorMessage;
          rule.ValidationParameters.Add("othervalue", this.OtherProperty);
          yield return rule;
      }
  
  }
  </code></pre>
  
  <p>So I should be able to do this:</p>
  
  <pre><code>    [MustBeGreaterIfTrue(OtherProperty="EverHadRestrainingOrder", ErrorMessage="Enter more info on your RO.")]
      public int? ROCounter { get; set; }
  </code></pre>