Aru*_*Kat 7 c# .net-5 blazor-webassembly
<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";
}
)
Run Code Online (Sandbox Code Playgroud)
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; }
}
Run Code Online (Sandbox Code Playgroud)
'''
我收到此错误..如果我使用本地日期时间变量(日期),此错误就会消失,但是我无法再将其映射到模型..任何解决方案如何将模型绑定到此
错误 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 个月,但答案是您需要绑定到 nullable DateTime。
所以你的财产需要public DateTime? CollectionDate { get; set; }并且应该有效。我刚刚遇到了同样的问题。
他们的 API 也说
注意:总是使用双向绑定@bind-Date来绑定到DateTime类型的字段?
请参阅: https: //www.mudblazor.com/components/datepicker#basic-usage
| 归档时间: |
|
| 查看次数: |
1217 次 |
| 最近记录: |