title: Date validation in ASP.NET MVC with DataAnnotations in ViewModel
body: <p>I have a DateTime property in my page's ViewModel. I would like to know if there is a built-in way of checking that the user entered a valid date.</p>
  
  <p>Here is what my current code looks like and as of now it is not automatically making sure the user enters a valid date (there is only required validation):</p>
  
  <p><strong>ViewModel property:</strong></p>
  
  <pre><code>[Required]
  [DataType(DataType.Date)]
  public DateTime MyDate{ get; set; }
  </code></pre>
  
  <p><strong>Razor MVC6 view:</strong></p>
  
  <pre><code>&lt;label asp-for="MyDate" class="control-label"&gt;&lt;/label&gt;
  &lt;input asp-for="MyDate" class="form-control" /&gt;
  &lt;span asp-validation-for="MyDate" class="text-danger" /&gt;
  </code></pre>