微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Antdesign Blazor 日期选择器选择窗格不会根据日期选择器值反映出来

如何解决Antdesign Blazor 日期选择器选择窗格不会根据日期选择器值反映出来

目前我在 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();
    }

input form

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。