- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在开发一个 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.InputDate
1[System.DateTime] requires a cascading parameter of type EditContext. For example, you can use Microsoft.AspNetCore.Components.Forms.InputDate
1[[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 指令,但您可以执行我上面所做的操作。
关于asp.net-core - Microsoft.AspNetCore.Components.Forms.InputDate 需要 EditContext 类型的级联参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66509582/
我是一名优秀的程序员,十分优秀!