'How do I Default the date to todays date for required field using EditForm?

I have a required property(using DataAnnotations) that defaults all the values without a ? mark after the type. it defaults to 01/01/0001. How can I make this blank or default to a certain date?

P.S I also had two int properties and they defaulted to 0. This makes no sense since I have no idea how it defaults.

Model property: enter image description here

Form field: enter image description here

enter image description here



Solution 1:[1]

Just add a default value in the model

[Required(ErrorMessage = "The Job Start Date field is Required")]
public DateTime StartDate { get; set; } = DateTime.Now;

Solution 2:[2]

Asides adding a default value you can override the OnInitialized blazor component method and set a default value in the component.

protected override void OnInitialized()
{
   request.StartDate = DateTime.Now;
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 Jesuseyitan