how can u bind dateonly and timeonly fields to html controls such ass date picker and time picker? i am using Mariadb as rdbms , I want to show to the end user date and time picker inputs, so far the date and time picker wont work properly.
<form method="post">
<input hidden asp-for="Period.Periodid" />
<div >
<div >
<h4 >Επεξεργασία Επαφής</h4>
</div>
<div asp-validation-summary="All" ></div>
<div >
<label asp-for="Period.StartDate">Ημερομηνία Έναρξης</label>
<input type="date" asp-for="Period.StartDate" />
<span asp-validation-for="Period.StartDate" ></span>
</div>
<div >
<label asp-for="Period.EndDate">Ημερομηνία Λήξης</label>
<input type="date" asp-for="Period.EndDate" />
<span asp-validation-for="Period.EndDate" ></span>
</div>
<div >
<label asp-for="Period.StartTime">Ώρα Έναρξης</label>
<input type="time" asp-for="Period.StartTime" />
<span asp-validation-for="Period.StartTime" ></span>
</div>
<div >
<label asp-for="Period.EndTime">Ώρα Λήξης</label>
<input type="time" asp-for="Period.EndTime" />
<span asp-validation-for="Period.EndTime" ></span>
</div>
<button type="submit" style="width:150px;">Ενημέρωση</button>
<a asp-page="Index" style="width:150px;">Λίστα</a>
</div>
model
public class Period
{
public int Periodid { get; set; }
[Required]
[DataType(DataType.Date)]
[DisplayFormat(DataFormatString = "{0:dd/MM/yyyy}", ApplyFormatInEditMode = true)]
public DateOnly StartDate { get; set; }
[Required]
[DataType(DataType.Date)]
[DisplayFormat(DataFormatString = "{0:dd/MM/yyyy}", ApplyFormatInEditMode = true)]
public DateOnly EndDate { get; set; }
[Required]
[DataType(DataType.Time)]
public TimeOnly StartTime { get; set; }
[Required]
[DataType(DataType.Time)]
public TimeOnly EndTime { get; set; }
}
CodePudding user response:
dateonly and timeonly are not supported yet for form binding (they will support it in dotnet 7)
see related post and solutions