I have a form defined as follows :
<EditForm EditContext="editContext" OnValidSubmit="HandleValidSubmit"><br /><DataAnnotationsValidator></DataAnnotationsValidator><ValidationSummary></ValidationSummary><div><label label="form-label" for="name">Name:</label><InputText class="form-control" id="Name" @bind-Value="bookingInfo.c.Name" /><ValidationMessage For="@(() => bookingInfo.c.Name)"></ValidationMessage></div><div><label label="form-label" for="name">Email:</label><InputText class="form-control" id="Email" @bind-Value="bookingInfo.c.Email" /><ValidationMessage For="@(() => bookingInfo.c.Email)"></ValidationMessage></div><div><label label="form-label" for="name">Contact:</label><InputText class="form-control" id="phone1" @bind-Value="bookingInfo.c.PhoneNumber1" /><ValidationMessage For="@(() => bookingInfo.c.PhoneNumber1)"></ValidationMessage></div><br /><button type="submit" class="submit-button">Submit</button></EditForm>The entity bookingInfo.c is defined as follows:
public class Customer { [Required] [MaxLength(50, ErrorMessage = "Name is too long")] [MinLength(4, ErrorMessage = "Name is too short")] public string Name { get; set; } [Key] [DatabaseGenerated(DatabaseGeneratedOption.Identity)] public int Id { get; set; } [Range(10,100, ErrorMessage = "Invalid age")] public int Age { get; set; } public DateTime CreatedDate { get; set; } [Required] [Phone] public string PhoneNumber1 { get; set; } [Phone] public string PhoneNumber2 { get; set; } [Required] [EmailAddress] public string Email { get; set; } public DateTime DateFirstContacted { get; set; } }The issue is that HandleValidSubmit is fired when I hit submit, even though the values are null. The entities are annotated with Required and ranges, then how does it pass the validation ? Am I missing something here ?