如何使用C#属性绑定输入类型时间,并在更改更改后的获取值
当我与C#属性绑定时,我无法获取值或更改输入类型时间的值。
<input type="time" class="form-control" @bind="EndTime" @bind:format="HH:mm">
c#属性
public DateTime EndTime { get; set; }
如果末日已经包含值,则如何绑定该属性,那么它将显示该属性,如果值更改,则末端时间值将会更改。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当您设置输入值以说“ 12:30”时,这不再是有效的日期格式(没有日期!),因此Blazor无法将其保存回
Endtime
。您将其设置为,大利士试图更新字段并失败,并且该值将设置回当前有效值,如果您只需要有一个时间属性,则使用
timeonly
并将输入类型设置为时间
,它将正常工作。请记住,日期/时间的实际格式由浏览器和语言环境设置控制。
这是我的测试页面:
When you set the input value to say "12:30", this is no longer a valid date format (there's no date!), so Blazor can't save it back to
EndTime
. You set it, Blazor tries to update the field and fails, and the value is set back to the current valid value,If you only want a Time property then use
TimeOnly
and set the input type totime
and it will work correctly.Remember, the actual formatting of Date/Time is controlled by the browser and the locale settings.
Here's my test page: