我正在编写一本书状,并有一个日历,注明日期为纽芬兰语,这样当用户点击所期望的支票或检查其自动填入我的模型的日期时。
我的问题是,当用户没有<输入代码>InputText的田地时,我会如何留下自己的验证错误?
// This iterated through the remaining days in the month to properly display the calendar
@for (int i = DateTime.Now.AddDays(1).Day; i <= daysInMonth; i++)
{
DateTime date = new DateTime(calendarMonth.Year, calendarMonth.Month, i);
<div class="active">
<button @onclick="() => SetDate(DateOnly.FromDateTime(date))">@i</button>
</div>
}
<EditForm Model="@booking" OnValidSubmit="CreateDates" FormName="CommitDates">
<div class="contact-form-button span-all">
<button type="submit" class="btn btn-main">Submit<i class="fa-solid fa-paper-plane btn-icon"></i></button>
</div>
<div class="span-all">
<DataAnnotationsValidator />
<ValidationSummary />
</div>
</EditForm>
@code {
[Parameter]
public int daysInMonth { get; set; }
// status parameter just checks whether we are modifying the check in or check out date value
[Parameter]
public bool status { get; set; }
[Parameter]
public DateOnly calendarMonth { get; set; }
[Parameter]
public BookingDatesVM booking { get; set; }
protected override Task OnInitializedAsync()
{
return base.OnInitializedAsync();
}
private void SetDate(DateOnly date)
{
if (status)
{
booking.CheckInDate = date;
}
else
{
booking.CheckOutDate = date;
}
}
private async Task CreateDates()
{
//await _bookingRepository.Create(booking);
}
}
This is my model, the session id is stored using ProtectedSessionStorage
and retrieved from the parent component and passed into this child component.
public class BookingDatesVM
{
[Required]
public Guid SessionId { get; set; }
[Required]
public DateOnly CheckInDate { get; set; }
[Required]
public DateOnly CheckOutDate { get; set; }
public Status BookingStatus { get; set; }
public DateTime CreatedDate { get; set; }
public enum Status
{
InProcess,
Pending,
New,
Approved,
Declined,
Cancelled
}
}
I have tried to research this issue and tried some EditContext
material i saw on here but still didn t give me any output regarding the errors.
I also tried adding the text boxes and populating them with the values but that also did not work.