I'm trying to use 2-way binding between a form and my object. I can get it to work for InputText
. But i get this errors when i add the ValueChanged
attribute for InputNumber
:
CS1662 Cannot convert lambda expression to intended delegate type because some of the return types in the block are not implicitly convertible to the delegate return type
CS1503 Argument 2: cannot convert from 'method group' to 'EventCallback'
When i compile this Component.razor
page:
@page "/test"
@using System.ComponentModel.DataAnnotations
<EditForm Model="@model">
<DataAnnotationsValidator />
<ValidationSummary />
<InputText Value="@model.Street" ValueExpression="@(() => model.Street)" ValueChanged="@StreetChanged" />
<InputNumber Value="@model.HouseNr" ValueExpression="@(() => model.HouseNr)" ValueChanged="@HouseNrChanged" />
<button type="submit">Send</button>
</EditForm>
@code {
protected void StreetChanged(string? value)
{
// ... code to lookup address and fill other fields
model.Street = value;
}
protected void HouseNrChanged(int? value)
{
// ... code to lookup address and fill other fields
model.HouseNr = value;
}
private Address model { get; set; } = new();
class Address
{
[Required]
public string? Street { get; set; }
[Required]
public int? HouseNr { get; set; }
}
}
I've tried to changing my HouseNrChanged
method, but i can't figure it out. It seems to have something to do with the different types of the ValueChanged
properties:
- InputText.ValueChanged has type
EventCallback<string>
- InputText.ValueChanged has type
EventCallback<TValue>
Questions:
- Any ideas on how to fix this?
- Is there any documentation?
- What does ValueExpression do besides causing a runtime error when it is omitted?
It's very hard to find examples