title: MVC RequiredIf Attribute - IsValid value parameter always null
body: <p>I am implementing a RequiredIf validation attribute and the value being passed to the IsValid method is always null.</p>
  
  <p>RequiredIfAttribute Class</p>
  
  <pre><code>    public class RequiredIfAttribute : ValidationAttribute
  {
      private RequiredAttribute innerAttribute = new RequiredAttribute();
      public string DependentProperty { get; set; }
      public object TargetValue { get; set; }
  
      public RequiredIfAttribute(string dependentProperty, object targetValue)
      {
          this.DependentProperty = dependentProperty;
          this.TargetValue = targetValue;
      }
  
      public override bool IsValid(object value)
      {
          return innerAttribute.IsValid(value);
      }
  }
  </code></pre>
  
  <p>ViewModel</p>
  
  <pre><code>        [Required]
      [Display(Name = "Are You A Student?")]
      public bool? IsStudent { get; set; }
  
      [RequiredIf("IsStudent", true, ErrorMessage = "You must upload a photo of your student ID if you wish to register as a student.")]
      [Display(Name = "Student ID")]
      [FileExtensions("jpg|jpeg|png|pdf", ErrorMessage = "File is not in the correct format.")]
      [MaxFileSize(2 * 1024 * 1024, ErrorMessage = "You may not upload files larger than 2 MB.")]
      public HttpPostedFileBase StudentId { get; set; }
  </code></pre>
  
  <p>EditorTemplate</p>
  
  <pre><code>    @model bool?
  @using System.Web.Mvc;
  @{
      var options = new List&lt;SelectListItem&gt;
      {
          new SelectListItem { Text = "Yes", Value = "true", Selected =  Model.HasValue &amp;&amp; Model.Value },
          new SelectListItem { Text = "No", Value = "false", Selected =  Model.HasValue &amp;&amp; Model.Value }
      };
  
      string defaultOption = null;
  
      if (ViewData.ModelMetadata.IsNullableValueType)
      {
          defaultOption = "(Select)";
      }
  }
  
  @Html.DropDownListFor(m =&gt; m, options, defaultOption)
  </code></pre>
  
  <p>Every time the form is submitted, the RequiredIf error message is thrown and I have a feeling it has to do with the null value I described initially. What am I doing wrong? Thanks!</p>
  
  <p>NOTE: The HTML appears to be rendering properly, so I don't think that's the problem.</p>
  
  <pre><code>    &lt;select data-val="true" data-val-required="The Are You A Student? field is required." id="IsStudent" name="IsStudent"&gt;&lt;option value=""&gt;(Select)&lt;/option&gt;
  &lt;option value="true"&gt;Yes&lt;/option&gt;
  &lt;option value="false"&gt;No&lt;/option&gt;
  &lt;/select&gt;
  </code></pre>