title: Get another property's value from ModelMetaData
body: <p>I'm trying to get to another property's value from within the <code>GetClientValidationRules</code> method of a custom validation attribute.</p>
  
  <p>Here is my attempt (based on <a href="https://stackoverflow.com/questions/5089086/modelmetadata-how-to-get-parent-metadata">Darin's response</a> on another question):</p>
  
  <pre><code>public IEnumerable&lt;ModelClientValidationRule&gt; GetClientValidationRules(
      ModelMetadata metadata, ControllerContext context)
  {
      var parentType = metadata.ContainerType;
      var parentMetaData = ModelMetadataProviders.Current
          .GetMetadataForType(null, parentType);
  
      var parentMetaData = ModelMetadataProviders.Current
          .GetMetadataForProperties(context.Controller.ViewData.Model, parentType); 
  
      var otherProperty = parentMetaData.FirstOrDefault(p =&gt; 
          p.PropertyName == "SomeProperty");
  
      var otherValue = otherProperty.Model;
  
      var rule = new ModelClientValidationRule
      {
          ValidationType = "customvalidatorattribute",
          ErrorMessage = this.FormatErrorMessage(metadata.GetDisplayName()),
      };
  
      yield return rule;
  }
  </code></pre>
  
  <p>However, when trying to set <code>otherValue</code>, I get:</p>
  
  <blockquote>
    <p>System.Reflection.TargetException: Object does not match target type.</p>
  </blockquote>