c# - 无法 MudDatePicker 如何将其绑定到数据模型
问题描述
<EditForm Model="@_newRegister" OnValidSubmit="@HandleValidSubmit">
<DataAnnotationsValidator />
<ValidationSummary />
<div class="container-fluid">
<div class="row">
<div class="col-6">
<div class="form-group">
<MudDatePicker Label="Collection Date" Editable="true" @bind-Date="_newRegister.CollectionDate" />
</div>
</div>
</div>
</div>
</Editform>
@code{
private Register _newRegister = new x.Shared.Register
{
ProcessingDate = DateTime.Today,
CollectionDate = DateTime.Today,
ModifiedDate = DateTime.Today,
CreateDate = DateTime.Today
};
private string Success = "";
DateTime? date = DateTime.Today;
public void HandleValidSubmit()
{
Success = "Success";
}
)
public class Register
{
[Key]
public int ID { get; set; }
public String CustomerName { get; set; }
public DateTime CollectionDate { get; set; }
public DateTime ProcessingDate { get; set; }
public String Location { get; set; }
public String Remarks { get; set; }
public String Reference { get; set; }
public int Type { get; set; }
}
'''
我收到此错误..如果我使用本地日期时间变量(日期),则此错误消失了,但是我无法再将其映射到模型..任何解决方案如何在此上绑定模型
错误 CS1662 无法将 lambda 表达式转换为预期的委托类型,因为块中的某些返回类型不能隐式转换为委托返回类型 X.Client
错误 CS1503 参数 2:无法从 'Microsoft.AspNetCore.Components.EventCallback<System.DateTime>' 转换为 'Microsoft.AspNetCore.Components.EventCallback' x.Client D:\x\Client\obj\Debug\net5.0\ Razor\Pages\CashRegister\AddRegister.razor.g.cs 174 活动
错误 CS1503 参数 2:无法从 'Microsoft.AspNetCore.Components.EventCallback<System.DateTime>' 转换为 'Microsoft.AspNetCore.Components.EventCallback' D:\x\Client\Pages\CashRegister\AddRegister.razor
错误 CS1662 无法转换lambda 表达式到预期的委托类型,因为块中的某些返回类型不能隐式转换为委托返回类型 D:\x\Client\Pages\CashRegister\AddRegister.razor
解决方案
我知道我迟到了大约 8 个月,但答案是你需要绑定到一个可以为空的DateTime
.
所以你的财产需要public DateTime? CollectionDate { get; set; }
,它应该工作。我只是有同样的问题。
他们的API也说
注意:总是使用双向绑定 @bind-Date 绑定到 DateTime 类型的字段?
请参阅:https ://resize-listener-mudblazor-test.azurewebsites.net/components/datepicker#basic-usage
推荐阅读
- python-3.x - 无法在画布中创建圆圈
- r - 如何使用R从excel中的单元格中提取多列?
- ios - Scrollview 内的 UIImageView - 缩放时偏离中心
- c - 在这个例子中我需要考虑字节顺序吗?
- c# - 使用 JSON 忽略序列化和反序列化中的参数名称
- git - 可以通过pr强制推送吗?想改写历史
- vim - Vimcript 中是否有用于块状视觉选择的功能?
- java - 如何在 JUnit 5 中使用 @RestTemplateClient?
- rust - Rust,2 个带有重叠私有函数的 crate
- reactjs - React router v5.0.1 - 在同一路由上渲染两个组件