可以在 Blazor 客户端中以特定格式绑定值。
例如
<input type="text" bind="@TestDate.ToString("dd.MM.yyyy")" />
@code
{
protected DateTime TestDate {get;set;} = DateTime.Now;
}
Run Code Online (Sandbox Code Playgroud)
我尝试做
<input type="text" bind="@TestDate" format-value="dd.MM.yyyy" />
Run Code Online (Sandbox Code Playgroud)
但这没有做任何事情,我收到了一个值,例如 11/12/2019 1:03:17 PM
它是bind:format,您在文档中有示例:数据绑定段落格式字符串
<input @bind="StartDate" @bind:format="yyyy-MM-dd" />
@code {
[Parameter]
public DateTime StartDate { get; set; } = new DateTime(2020, 1, 1);
}
Run Code Online (Sandbox Code Playgroud)