Skip to content

Instantly share code, notes, and snippets.

@scottsauber
Created August 25, 2023 02:53
Show Gist options
  • Save scottsauber/925d842071ea73a6a2466e601b22a6fb to your computer and use it in GitHub Desktop.
Save scottsauber/925d842071ea73a6a2466e601b22a6fb to your computer and use it in GitHub Desktop.
Data bind child to parent's data
// In our child component
<input value="@Value" oninput="@OnValueChanged" />
@code {
[Parameter]
public decimal Value { get; set; }
[Parameter]
public EventCallback<decimal> ValueChanged { get; set; }
private Task OnValueChanged(ChangeEventArgs e)
{
Value = Convert.ToDecimal(e.Value ?? 0);
return ValueChanged.InvokeAsync(Value);
}
}
// In our parent component
<ChildComponent @bind-Value="transaction.SomePropertyName" />
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment