问题描述
目前我在 Blazor 服务器端工作。我有一个问题,当我选择 Effective Year to 2022 时,startdate 和 enddate 值可以更改为 2022-04-19,但是当我打开日期选择器选择时,它显示为 2021 年 4 月。 当我从选择中选择任何一天时,日期选择器选择是有效的,然后再次更改年份。 莫名其妙,有人知道是什么原因吗? 这是我的 .blazor
@inherits AppComponentBase
<Modal @ref="ModalRef" Title="@Title" Visible="Visible" Draggable="true"
OkText="@OK" OnOk="OkButtonOnClick" OnCancel="CancelButtonOnClick"
MaskClosable="false" Keyboard="false" Width="800">
<Form @ref="FormRef" Model="@InputModel"
Loading="Loading" ValidateOnChange="true"
OnFinish="OnFinish" OnFinishFailed="OnFinishFailed"
LabelColSpan="6" WrapperColSpan="18">
<Validator>
<FluentValidationValidator />
</Validator>
<ChildContent>
<FormItem Label="Effective Year" required>
<Select @bind-Value="@context.EffectiveYear"
DefaultValue="@DefaultEffectiveYear"
TItemValue="int"
TItem="int"
Onselecteditemchanged="selecteditemchangedHandler"
Style="width: 200px;">
<SelectOptions>
@foreach (var item in EffectiveYearsDropdown)
{
<SelectOption TItemValue="int" TItem="int"
Value=@item Label=@item.ToString() />
}
</SelectOptions>
</Select>
</FormItem>
<FormItem Class="input-uppercase" Label="Duration" required>
<AntDesign.InputNumber @bind-Value="@context.Duration"
TValue="int"
Max="99"
Style="width: 200px;">
</AntDesign.InputNumber>
</FormItem>
<FormItem Class="input-uppercase" Label="Start Date" required>
<AntDesign.Col Span="8">
<DatePicker @bind-Value="@context.StartDate"
Picker="@DatePickerType.Date"
DefaultValue="@context.StartDate"
Format="@Constants.DATE_FORMAT"
Style="width: 200px;" />
</AntDesign.Col>
</FormItem>
<FormItem Class="input-uppercase" Label="End Date" required>
<AntDesign.Col Span="8">
<DatePicker @bind-Value="@context.EndDate"
Picker="@DatePickerType.Date"
DefaultValue="@context.StartDate"
Format="@Constants.DATE_FORMAT"
Style="width: 200px;" />
</AntDesign.Col>
</FormItem>
<FormItem Class="input-uppercase" Label="Remarks" required>
<Input @bind-Value="@context.Remarks" MaxLength="60" />
</FormItem>
</ChildContent>
</Form>
这里是我的 .blazor.cs
protected override void OnInitialized()
{
for (int i = DefaultEffectiveYear; i <= DefaultEffectiveYear + Constants.DROPDOWN_YEARS; i++)
{
EffectiveYearsDropdown.Add(i);
}
}
private void selecteditemchangedHandler(int year)
{
if (year != DateTime.Now.Year)
{
//var newDate = new DateTime(year,1,1);
var newDate = new DateTime(year,DateTime.Now.Month,DateTime.Now.Day);
InputModel.StartDate = newDate;
InputModel.EndDate = newDate;
//DefaultStartDate = newDate;
}
else
{
InputModel.StartDate = DateTime.Now;
InputModel.EndDate = DateTime.Now;
}
StateHasChanged();
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)