I would like to combine @bind-Value and @onchange in an input field in blazor. But when i do that i seems to get this error message The attribute names could not be inferred from bind attribute 'bind-Value'. Bind attributes should be of the form 'bind' or 'bind-value' along with their corresponding optional parameters like 'bind-value:event', 'bind:format' etc.
. I have found one solution for a work around like this <input class="form-control" type="number" @bind:event="oninput" @onchange="MethodIWantToTrigger" @bind="@MyProperty" />
But the problem i get with this is that is not possible to write 0, ex i cant write 0.01 in the input field. Is there any other solution to make this combination?
2
Answers
Actually your approach is quite proper. For the decimal situation, you can create your own custom component easily.
Here is an example article for custom component to achive binding decimal numbers.
Also please refer to Blazer University InputBase component article for better understanding
@bind
is just Razor syntactic sugar. The Razor compiler builds a set of handlers in the compiled C# file.Here are two examples of how you can code what I believe you want to do.