title: Required string attribute with null value gives IsValid=true in ASP.NET Core 2 Razor Page
body: <p>I'm really confused by this. I have a Razor Page on ASP.NET Core 2 that has a required property called <code>SchemaId</code>. I've tried marking it as <code>[Required]</code>, <code>[BindRequired]</code>, and <code>[Required(AllowEmptyStrings = false)]</code>, yet when I post my form, I see that <code>SchemaId</code> is <code>null</code> and yet <code>ModelState.IsValid == true</code>. Here's the <code>Upload.cshtml.cs</code>:</p>
  
  <pre><code>namespace Uploader.Pages
  {
      public class UploadModel : PageModel
      {
          private IUploader _uploader;
  
          public UploadModel(IUploader uploader)
          {
              _uploader = uploader;
          }
  
          [BindProperty]
          public IEnumerable&lt;IFormFile&gt; UploadedFiles { get; set; }
  
          [Required(AllowEmptyStrings = false)]
          [BindProperty]
          [BindRequired]
          public string SchemaId { get; set; }
  
  
          public void OnGet(string schemaId = null)
          {
              SchemaId = schemaId;
          }
  
          public async Task&lt;IActionResult&gt; OnPostAsync()
          {
              // SchemaId is NULL right here!
              if (!ModelState.IsValid) // Yet IsValid = true!
              {
                  return Page();
              }
  
              // Use _uploader to actually upload the file
  
              return RedirectToPage("/Next", new { uploadId = uploadId, schemaId = SchemaId });
          }
      }
  }
  </code></pre>
  
  <p>Relevant extract from <code>Upload.cshtml</code> file:</p>
  
  <pre><code>&lt;div asp-validation-summary="All"&gt;&lt;/div&gt;
  &lt;form enctype="multipart/form-data" method="POST" asp-page="Upload"&gt;
      &lt;input class="inputfile" type="file" id="UploadedFiles" multiple="multiple" name="UploadedFiles"&gt;
      &lt;label for="UploadedFiles"&gt;
          &lt;span&gt;Choose a file...&lt;/span&gt;
      &lt;/label&gt;
      &lt;input type="hidden" asp-for="SchemaId"&gt;
      &lt;button type="submit" class="inputfilesubmit"&gt;Upload&lt;/button&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>How can I get the model validation to work properly?</p>