Gcobani Mkontwana

Gcobani Mkontwana

  • 567
  • 1.9k
  • 404.4k

Better way to handle error on web app?

Jul 22 2020 10:42 AM
HI Team
 
I have created some logic around handling error, but im not getting any error. The idea when a user leave @EditorFor must validate the message with image error. I have done this following, but its not working debug nothing, maybe missing something pls assist.
  1. // Model  
  2.   
  3. [Required(ErrorMessage = " This field is required")]  
  4.         [EmailAddress(ErrorMessage = "Invalid email address")]  
  5.         public string Email { getset; }  
  6.   
  7. // View on Form  
  8.   
  9. <div class="form-group row">  
  10.                                 <label for="Email" class="col-sm-2 col-form-label">Email:</label>  
  11.                                 <div class="col-sm-4">  
  12.                                     @Html.EditorFor(model => model.RegForm.Email, new { htmlAttributes = new { @class = "form-control", autofocus = "autofocus", placeholder = "Email" } })  
  13.                                     @Html.ValidationMessageFor(model => model.RegForm.Email, ""new { @class = "text-danger" })  
  14.                                 </div>  
  15.                             </div>  
  16.   
  17.   
  18.   
  19. // Javascript  
  20.   
  21. <!---JavaScript error handling-->  
  22.   
  23.                 <script type="text/javascript" src="~/Content/dist/js/jquery.validate.min.js">  
  24.                 </script>  
  25.                 <script type="text/javascript" src="~/Content/dist/js/jquery.validate.unobtrusive.min.js">  
  26.                 </script>  
 

Answers (2)