title: MVC3 ValidationAttribute validationContext.memberName is null
body: <p>I find half solutions everywhere but I cannot get a real answer for this.</p>
  
  <p>I have created a validation attribute inheriting from ValidationAttribute and IClientValidatable.</p>
  
  <p>Everything seems to work fine, and if I put a validation summary on the page the error displays.</p>
  
  <p>however I cannot get the error displaying beside the textbox relating to the property.</p>
  
  <p>I think this is because I need to add the property name to the validation result.</p>
  
  <p>HOWEVER this is where it fails, because I cannot get the member name from the validationContext.</p>
  
  <p>is there a way to enable this to happen? Or am I missing something?</p>
  
  <pre><code>public class AdmissionDayCaseAttribute : ValidationAttribute, IClientValidatable
  {
      private String DayCaseID;
      private String AdmissionDateID;
      private String DischargeDateID;
  
      public AdmissionDayCaseAttribute(String DayCaseID, String AdmissionDateID, String DischargeDateID)
      {
          this.DayCaseID = DayCaseID;
          this.AdmissionDateID = AdmissionDateID;
          this.DischargeDateID = DischargeDateID;
      }
      protected override ValidationResult IsValid(object value, ValidationContext validationContext)
      {
          object AdmissionDate = GetPropertyValue(validationContext.ObjectInstance, AdmissionDateID);
          object DischargeDate = GetPropertyValue(validationContext.ObjectInstance, DischargeDateID);
          object AdmissionType = validationContext.MemberName == null ? null : GetPropertyValue(validationContext.ObjectInstance, validationContext.MemberName);
          if (AdmissionDate != null &amp;&amp; DischargeDate != null &amp;&amp; AdmissionType != null)
          {
              if (AdmissionDate.Equals(DischargeDate) &amp;&amp; DayCaseID.Equals(AdmissionType.ToString()))
              {
                  return new ValidationResult(ErrorMessage, new List&lt;String&gt;() { validationContext.MemberName });
              }
          }
          return ValidationResult.Success;
      }
      private object GetPropertyValue(object instance,String propertyName)
      {
          Type itype = instance.GetType();
          return itype.GetProperty(propertyName).GetValue(instance,null);
      }
      public IEnumerable&lt;ModelClientValidationRule&gt; GetClientValidationRules(ModelMetadata metadata, ControllerContext context)
      {
          ModelClientValidationRule vr = new ModelClientValidationRule()
          {
              ErrorMessage = ErrorMessage,
              ValidationType = "admissiondaycase"
          };
          vr.ValidationParameters.Add(new KeyValuePair&lt;string, object&gt;("admissiondateid", AdmissionDateID));
          vr.ValidationParameters.Add(new KeyValuePair&lt;string, object&gt;("dischargedateid", DischargeDateID));
          vr.ValidationParameters.Add(new KeyValuePair&lt;string, object&gt;("daycaseid", DayCaseID));
          yield return vr;
      }
  </code></pre>
  
  <p><strong>EDIT/UPDATE</strong></p>
  
  <p>the view looks like this - </p>
  
  <pre><code>&lt;tr&gt;
      &lt;td&gt;
          @Html.LabelFor(x =&gt; x.AdmissionTypeID)
      &lt;/td&gt;
      &lt;td&gt;
          @Html.CustomDropDownListFor(a =&gt; a.AdmissionTypeID, Lookup.AdmissionTypes,Default.Constant.DROPDOWN)
          @Html.ValidationMessageFor(a=&gt;a.AdmissionTypeID)
      &lt;/td&gt;
  &lt;/tr&gt;
  </code></pre>
  
  <p>There no javascript or anything interacting with this, its pretty basic however some extra details -
  this view code is in a view template, which is used IN a partial view</p>