title: ASP.NET Core Model Validation Errors displaying in wrong order
body: <p><strong>Issue:</strong>
  The Model errors are not displayed according to the model definition, they are displayed randomly. </p>
  
  <p>This is happening in ASP.NET core app. I never had this issue in regular asp.net mvc application.</p>
  
  <p>Is there any setting i have to enable in asp.net core razor pages? Or am i doing some thing wrong completely. Please help.</p>
  
  <p><strong>UI Display</strong>
  Errors are displayed in random format:</p>
  
  <ul><li>DOB is required</li><li>Last Name is required</li><li>Child EI ID is required</li><li>First Name is required</li><li>School District is required</li><li>Date Of Referral is required</li></ul>
  
  <p><strong>ViewModel Defintion:</strong></p>
  
  <pre><code>public class DocumentViewModel 
  {
      [Required(ErrorMessage = "First Name is required")]
      [RegularExpression(@"^[a-zA-Z- ']+$", ErrorMessage = "First Name should not contain any special character or number.")]
      public string FirstName { get; set; }
  
      [Required(ErrorMessage = "Last Name is required")]
      [RegularExpression(@"^[a-zA-Z- ']+$", ErrorMessage = "Last Name should not contain any special character or number.")]
      public string LastName { get; set; }
  
      [Required(ErrorMessage = "Child EI ID is required")]
      public int? ChildEIID { get; set; }
  
     [Required(ErrorMessage = "DOB is required")]
     [DataType(DataType.Date)]
      public DateTime? DOB { get; set; }
  
      [Required(ErrorMessage = "District is required")]
      public string District { get; set; }
  
      [Required(ErrorMessage = "Date Of Referral is required")]
      [DataType(DataType.Date)]
      public DateTime? DateOfReferral{ get; set; }
  </code></pre>
  
  <p>}</p>
  
  <p><strong>POST METHOD</strong></p>
  
  <pre><code> [HttpPost]
   [AutoValidateAntiforgeryToken]
      public ActionResult Documents(UploadDocumentViewModel viewModel)
      {
  
  
          //string errorMessages = "";
          if (!ModelState.IsValid)
          {
              return ModelErrors();
          }
  
          return Json(new { status = "success", message = "Documents Uploaded." });
      }
  </code></pre>
  
  <p><strong>MODEL ERRORS RETURN METHOD</strong></p>
  
  <pre><code>private ActionResult ModelErrors()
      {
          var modelStateErrors = this.ModelState.Keys.SelectMany(key =&gt; this.ModelState[key].Errors);
          var message = "&lt;ul&gt;";
  
          foreach (var modelStateError in modelStateErrors)
          {
              message += "&lt;li&gt;" + modelStateError.ErrorMessage + "&lt;/li&gt;";
          }
          message += "&lt;/ul&gt;";
          return Json(new { status = "error", message = message });
      }
  </code></pre>