title: ASP.Net Core Razor model validation for a <select> element
body: <p>I have a .Net Core web application and I am trying to get the model validation to work as I want.</p>
  <p>The razor code is</p>
  <pre><code>  &lt;div class=&quot;form-group&quot;&gt;
        &lt;label asp-for=&quot;Duration&quot;&gt;&lt;/label&gt;
        &lt;select asp-for=&quot;Duration&quot; class=&quot;form-control&quot;&gt;
            &lt;option value=&quot;&quot;&gt;Pick number of days&lt;/option&gt;
            &lt;option value=&quot;7&quot;&gt;7 days&lt;/option&gt;
            &lt;option value=&quot;14&quot;&gt;14 days&lt;/option&gt;
            &lt;option value=&quot;21&quot;&gt;21 days&lt;/option&gt;
            &lt;option value=&quot;28&quot;&gt;28 days&lt;/option&gt;
        &lt;/select&gt;
        &lt;div&gt;&lt;span asp-validation-for=&quot;Duration&quot; class=&quot;text-danger&quot;&gt;&lt;/span&gt;&lt;/div&gt;
    &lt;/div&gt;
  </code></pre>
  <p>The model is</p>
  <pre><code>  [Required(ErrorMessage = &quot;The duration is required&quot;)]
    [Display(Name = &quot;Length of audit:&quot;)]
    public int Duration { get; set; }
  </code></pre>
  <p>If I do not select any value, the drop down remains at &quot;<em>Pick number of days</em>&quot;. The validation message that is shown is &quot;<strong>The value '' is invalid.</strong>&quot;</p>
  <p>Apart from creating my own custom validator, how can I get the code to generate the validation message of &quot;<strong>The duration is required</strong>&quot;</p>