title: Group validation messages for multiple properties together into one message asp.net mvc
body: <p>I have a view model that has year/month/day properties for someone's date of birth. All of these fields are required. Right now, if someone doesn't enter anything for the date of birth they get 3 separate error messages.</p>
  
  <p><img src="https://i.stack.imgur.com/yMqbS.png" alt="Date of birth fields"></p>
  
  <p>What I want to do is somehow group those error messages together into 1 message that just says 'Date of birth is required'. So if 1 or more of those fields are blank, they will always just get the 1 validation message.</p>
  
  <p>I NEED this to work on client-side validation via jquery validate and unobtrusive validate. I know this is possible with the jquery validate plugin by looking at this <a href="https://stackoverflow.com/questions/17598758/one-validation-message-for-multiple-fields">question</a>. But I don't know how to achieve this with asp.net mvc using validation attributes on my model and unobtrusive validation. Hopefully there's some built in way to group properties for validation purposes, but if not can this be done with a custom validation attribute?</p>
  
  <p>Here's what my existing model and view looks like:</p>
  
  <p>The Model:</p>
  
  <pre><code>public class MyModel {
      [Required(ErrorMessage = "Year is required")]
      public int Year { get; set; }
      [Required(ErrorMessage = "Month is required")]
      public int Month { get; set; }
      [Required(ErrorMessage = "Day is required")]
      public int Day { get; set; }
  }
  </code></pre>
  
  <p>The View:</p>
  
  <pre><code>&lt;div&gt;
      &lt;label&gt;Date of birth: &lt;span style="color:red;"&gt;*&lt;/span&gt;&lt;/label&gt;
      &lt;div&gt;@Html.DropDownListFor(m =&gt; m.Year, ApplicationModel.GetSelectListForDateRange(DateTime.Today.Year - 16, DateTime.Today.Year - 10), "", new{data_description="birthDate"})@Html.LabelFor(m =&gt; m.StudentBirthYear)&lt;/div&gt;
      &lt;div&gt;@Html.DropDownListFor(m =&gt; m.Month, ApplicationModel.GetSelectListForDateRange(1, 12, true), "", new{data_description="birthDate"})@Html.LabelFor(m =&gt; m.StudentBirthMonth)&lt;/div&gt;
      &lt;div&gt;@Html.DropDownListFor(m =&gt; m.Day, ApplicationModel.GetSelectListForDateRange(1, 31), "", new{data_description="birthDate"})@Html.LabelFor(m =&gt; m.StudentBirthDay)&lt;/div&gt;
  &lt;/div&gt;
  &lt;div class="error-container"&gt;@Html.ValidationMessageFor(m =&gt; m.Year)&lt;/div&gt;
  &lt;div class="error-container"&gt;@Html.ValidationMessageFor(m =&gt; m.Month)&lt;/div&gt;
  &lt;div class="error-container"&gt;@Html.ValidationMessageFor(m =&gt; m.Day)&lt;/div&gt;
  </code></pre>