title: ASP.NET MVC 2 "value" in IsValid override in DataAnnotation attribute passed is null, when incorrect date is submitted
body: <p>This is my first question here on stack overflow.
  i need help on a problem i encountered during an ASP.NET MVC2 project i am currently working on.
  I should note that I'm relatively new to MVC design, so pls bear my ignorance.
  Here goes :
  I have a regular form on which various details about a person are shown. One of them is "Date of Birth". My view is like this</p>
  
  <pre><code>&lt;div class="form-items"&gt;
              &lt;%: Html.Label("DateOfBirth", "Date of Birth:") %&gt;
              &lt;%: Html.EditorFor(m =&gt; m.DateOfBirth) %&gt;
              &lt;%: Html.ValidationMessageFor(m =&gt; m.DateOfBirth) %&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>I'm using an editor template i found, to show only the date correctly :</p>
  
  <pre><code>&lt;%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl&lt;System.DateTime?&gt;"%&gt;
  &lt;%= Html.TextBox("", (Model.HasValue ? Model.Value.ToShortDateString() : string.Empty))%&gt;
  </code></pre>
  
  <p>I used LinqToSql designer to create my model from an sql database. In order to do some validation i made a partial class Person to extend the one created by the designer (under the same namespace) :</p>
  
  <pre><code>[MetadataType(typeof(IPerson))]
  public partial class Person : IPerson
  {        //To create buddy class    }
  
  public interface IPerson
  {
      [Required(ErrorMessage="Please enter a name")]
      string Name { get; set; }
      [Required(ErrorMessage="Please enter a surname")]
      string Surname { get; set; }
      [Birthday]
      DateTime? DateOfBirth { get; set; }
      [Email(ErrorMessage="Please enter a valid email")]
      string Email { get; set; }
  }
  </code></pre>
  
  <p>I want to make sure that a correct date is entered. So i created a custom DataAnnotation attribute in order to validate the date :</p>
  
  <pre><code>public class BirthdayAttribute : ValidationAttribute
  {
      private const string _errorMessage = "Please enter a valid date";
  
      public BirthdayAttribute() : base(_errorMessage) { }
  
      public override bool  IsValid(object value)
      {
          if (value == null)
          {
              return true;
          }
          DateTime temp;
          bool result = DateTime.TryParse(value.ToString(), out temp);
          return result;
      }
  }
  </code></pre>
  
  <p>Well, my problem is this. Once i enter an incorrect date in the DateOfBirth field then no custom message is displayed even if use the attribute like [Birthday(ErrorMessage=".....")]. The message displayed is the one returned from the db ie "The value '32/4/1967' is not valid for DateOfBirth.". I tried to enter some break points around the code, and found out that the "value" in attribute is always null when the date is incorrect, but always gets a value if the date is in correct format. The same ( value == null) is passed also in the code generated by the designer.</p>
  
  <p>This thing is driving me nuts. Please can anyone help me deal with this?
  Also if someone can tell me where exactly is the point of entry from the view to the database. Is it related to the model binder? because i wanted to check exactly what value is passed once i press the "submit" button.
  Thank you.</p>