本文介绍了如何将时间类型的输入与blazor绑定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,我想将 int 类型的 2 变量绑定到 min max time 类型的 input 的值.
我该怎么办?

我不知道在 bind 字段中放置什么,因为有2个不同的变量.还有 min max 属性.

Hello i have 2 variables of type int that i would like to bind to the min and max values of an input of type time.
How can i do this?

I do not know what to place in the bind field since there are 2 different variables.Also there is the min and max attributes.

<输入类型="time" min ="@ model.min" max ="@ model.max" bind =?/>

<input type="time" min="@model.min" max="@model.max" bind=?/>

我应该在 bind 中放入什么?

更新经过更彻底的分析,我决定我需要2个类型为 Timespan 的变量,并将它们绑定到2个类型为 time 的输入.

Update On a more thoroughly analysis i decided i will need 2 variables of type Timespan and i will bind these to 2 inputs of type time.

推荐答案

您不能将TimeSpan直接绑定到Blazor中的输入,但是可以使用属性将其转换为字符串.

You cannot bind a TimeSpan directly to an input in Blazor, but you can use a property to convert it to/from a string.

<input type="time" min="@model.min" max="@model.max" bind="@TimeProxy" />

@functions
{
  string TimeProxy { get => model.Time.ToString(); set => TimeSpan.TryParse(value,out model.Time); }
}

这篇关于如何将时间类型的输入与blazor绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-24 16:24