gpt4 book ai didi

asp.net-core - Microsoft.AspNetCore.Components.Forms.InputDate 需要 EditContext 类型的级联参数

转载 作者:行者123 更新时间:2023-12-04 03:38:24 29 4
gpt4 key购买 nike

我正在开发一个 ASP.NET 5.0 blazor web assembly应用程序。我需要在仪表板屏幕中有一个日期选择器来选择一个日期来显示详细信息。
这是我的代码:

<input class="input" type="month" id="staffPicker" name="staffPicker"
aria-label="Staff Sales Detail Period"
@bind="StaffSaleDetailsPeriod"
max="@DateTime.Now.ToString("yyyy-MM")">
我需要在更改日期时触发 API 调用。所以我尝试添加 @onchange到上面的代码如下所示。
<input class="input" type="month" id="staffPicker" name="staffPicker"
aria-label="Staff Sales Detail Period"
@bind="StaffSaleDetailsPeriod"
max="@DateTime.Now.ToString("yyyy-MM")"
@onchange="OnStaffSalePeriodChange">
但这会产生新的错误,如下所示:

The attribute 'onchange' is used two or more times for this element.Attributes must be unique (case-insensitive). The attribute 'onchange'is used by the '@bind' directive attribute.


所以我尝试替换上面的 input带有 <InputDate> 的元素如下所示,
<InputDate class="input is-small"
ValueExpression="() => StaffSaleDetailsPeriod"
Value="StaffSaleDetailsPeriod"
ValueChanged="(DateTime staffSalesPeriod) => OnStaffSalePeriodChange()"
max="@DateTime.Now.ToString("yyyy-MM")"/>
这会产生如下所示的运行时错误:

Microsoft.AspNetCore.Components.Forms.InputDate1[System.DateTime] requires a cascading parameter of type EditContext. For example, you can use Microsoft.AspNetCore.Components.Forms.InputDate1[[System.DateTime, System.Private.CoreLib, Version=5.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]] inside an EditForm


请帮助我解决我所缺少的或此 <InputDate>不能与 EditForm 一起使用?有什么解决方法吗?请建议。

最佳答案

<input class="input" type="month" id="staffPicker" name="staffPicker"
aria-label="Staff Sales Detail Period"
@bind="StaffSaleDetailsPeriod"
max="@DateTime.Now.ToString("yyyy-MM")"
@onchange="OnStaffSalePeriodChange">
当您使用 @bind 编译器指令时,编译器会在幕后创建一些代码,其结果就像您执行了以下操作:
<input class="input" type="month" id="staffPicker" name="staffPicker"
aria-label="Staff Sales Detail Period"
value="StaffSaleDetailsPeriod"
max="@DateTime.Now.ToString("yyyy-MM")"
@onchange="@((args) => OnStaffSalePeriodChange=args.Value.ToString())">
因此,如果您使用@bind,则不能使用@onchange 指令,但您可以执行我上面所做的操作。
至于第二个问题:InputDate 组件必须嵌入在其 Model 属性 的 EditForm 中。或 EditContext 具有必要的值(value)

关于asp.net-core - Microsoft.AspNetCore.Components.Forms.InputDate 需要 EditContext 类型的级联参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66509582/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com