title: ASP.NET Blazor Required Validation with InputSelect
body: <p>I am trying to get the Required attribute to work with InputSelect but validation doesn't work in Blazor Server. The form can be submitted without selection. Interestingly it works when the model property is nullable. Before .NET 5.0 it didn't work with nullable types because the InputSelect didn't support them. I however want a non-nullable required property because I want to reuse the dto from my API as a model and because it is logically wrong.</p>
  <p><a href="https://i.stack.imgur.com/f0zfL.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/f0zfL.png" alt="enter image description here" /></a></p>
  <pre><code>public class SomeModel
  {
      [Required]
      public string SomeString { get; set; }
  
      [Required]
      public SomeEnum SomeEnum { get; set; }
  
      [Required]
      public SomeEnum? SomeNullableEnum { get; set; }
  
      [Required]
      public int SomeInt { get; set; }
  
      [Required]
      public int? SomeNullableInt { get; set; }
  }
  
  public enum SomeEnum
  {
      A = 1,
      B = 2
  }
  </code></pre>
  <p>The page</p>
  <pre><code>@page &quot;/testrequired&quot;
  @using TestNET5BlazorServerApp.Data;
  
  
  &lt;EditForm Model=&quot;Model&quot; OnValidSubmit=&quot;Submit&quot;&gt;
  
      &lt;DataAnnotationsValidator /&gt;
      &lt;ValidationSummary /&gt;
  
      String:
      &lt;br /&gt;
      &lt;InputText @bind-Value=&quot;Model.SomeString&quot; /&gt;
      &lt;br /&gt;
      &lt;br /&gt;
      Enum:
      &lt;br /&gt;
      &lt;InputSelect @bind-Value=&quot;Model.SomeEnum&quot;&gt;
          &lt;option value=&quot;&quot;&gt;Select Enum&lt;/option&gt;
          &lt;option value=&quot;@SomeEnum.A&quot;&gt;@SomeEnum.A&lt;/option&gt;
          &lt;option value=&quot;@SomeEnum.B&quot;&gt;@SomeEnum.B&lt;/option&gt;
      &lt;/InputSelect&gt;
      &lt;br /&gt;
      &lt;br /&gt;
  
      Nullable Enum:
      &lt;br /&gt;
      &lt;InputSelect @bind-Value=&quot;Model.SomeNullableEnum&quot;&gt;
          &lt;option&gt;Select Nullable Enum&lt;/option&gt;
          &lt;option value=&quot;@SomeEnum.A&quot;&gt;@SomeEnum.A&lt;/option&gt;
          &lt;option value=&quot;@SomeEnum.B&quot;&gt;@SomeEnum.B&lt;/option&gt;
      &lt;/InputSelect&gt;
      &lt;br /&gt;
      &lt;br /&gt;
  
      Int:
      &lt;br /&gt;
      &lt;InputSelect @bind-Value=&quot;Model.SomeInt&quot;&gt;
          &lt;option&gt;Select Int&lt;/option&gt;
          &lt;option value=&quot;1&quot;&gt;1&lt;/option&gt;
          &lt;option value=&quot;2&quot;&gt;2&lt;/option&gt;
      &lt;/InputSelect&gt;
      &lt;br /&gt;
      &lt;br /&gt;
  
      Nullable Int:
      &lt;br /&gt;
      &lt;InputSelect @bind-Value=&quot;Model.SomeNullableInt&quot;&gt;
          &lt;option&gt;Select Nullable Int&lt;/option&gt;
          &lt;option value=&quot;1&quot;&gt;1&lt;/option&gt;
          &lt;option value=&quot;2&quot;&gt;2&lt;/option&gt;
      &lt;/InputSelect&gt;
      &lt;br /&gt;
      &lt;br /&gt;
  
      &lt;button type=&quot;submit&quot;&gt;Save&lt;/button&gt;
  &lt;/EditForm&gt;
  
  @code 
  {
      SomeModel Model = new Data.SomeModel();
  
      void Submit()
      {
          System.Diagnostics.Debug.WriteLine(&quot;Enum &quot; + Model.SomeEnum);
          System.Diagnostics.Debug.WriteLine(&quot;Nullable Enum &quot; + Model.SomeNullableEnum);
          System.Diagnostics.Debug.WriteLine(&quot;Int &quot; + Model.SomeInt);
          System.Diagnostics.Debug.WriteLine(&quot;Nullable Int &quot; + Model.SomeNullableInt);
      }
  }
  </code></pre>