So expanding @Zsolt Bendes answer with my opinion: I think that the conversion should be handled on the view level. The model should not know about the view implementation (e.g. percentage value property in the model is in range 0...1). I think it's better to implement these additional properties on your code behind (or @code block) to act as a converter. This way gets kind of repetitive if you have several properties that need to be converted to e.g. percentage values, but I have not discovered a better way. So my suggested code is (with partial class):
<EditForm Model="@Example" OnValidSubmit="@HandleValidSubmit">
<DataAnnotationsValidator />
<ValidationSummary />
<div class="row">
<label for="prop">Property as percentage:</label>
<InputNumber id="prop" @bind-Value=PercentageProperty/>
<p>%</p>
</div>
<button type="submit">Submit</button>
</EditForm>
public partial class Component : ComponentBase
{
public ExampleModel Example { get; set; }
public double PercentageProperty { get => Example.ModelProperty * 100; set => Example.ModelProperty = value / 100; }
public void HandleValidSubmit()
{
// Code to handle submit
}
}
public class ExampleModel
{
public double ModelProperty { get; set; }
}
Hopefully Blazor team manages to make InputNumber component binding able to handle delegates, or some other way to handle reusable converters...