Hopefully this helps, I was also trying to bind a Timespan a input of type="time"
I managed to achieve it with the help from the following site
https://www.meziantou.net/creating-a-inputselect-component-for-enumerations-in-blazor.htm
This is the code I created to achieve this
InputTime.cs
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Forms;
using Microsoft.AspNetCore.Components.Rendering;
using System;
using System.Globalization;
namespace Example
{
public sealed class InputTime : InputBase<TimeSpan>
{
protected override void BuildRenderTree(RenderTreeBuilder builder)
{
builder.OpenElement(0, "input");
builder.AddAttribute(1, "type", "time");
builder.AddMultipleAttributes(2, AdditionalAttributes);
builder.AddAttribute(3, "class", CssClass);
builder.AddAttribute(4, "value", BindConverter.FormatValue(CurrentValueAsString));
builder.AddAttribute(5, "onchange", EventCallback.Factory.CreateBinder<string>(this, value => CurrentValueAsString = value, CurrentValueAsString, null));
builder.CloseElement(); // close the select element
}
protected override bool TryParseValueFromString(string value, out TimeSpan result, out string validationErrorMessage)
{
validationErrorMessage = null;
return BindConverter.TryConvertTo<TimeSpan>(value, CultureInfo.CurrentCulture, out result);
}
}
}
Razor Page
<div class="form-group">
<label>Time From</label>
<InputTime @bind-Value="MyModel.TimeFrom" class="form-control"></InputTime>
<ValidationMessage For="() => MyModel.TimeFrom"></ValidationMessage>
</div>
Timespan
and i need to somehow limit the user to an interval[ from hour - to Hour]
...e.g[ 13.00 17.00]