Reputation: 133
I am trying to use blazor to present a textbox to the user and then call the function Input with the user's input. This code is taken from the "Lambda Expressions" section of this document: https://learn.microsoft.com/en-us/aspnet/core/blazor/components/event-handling?view=aspnetcore-6.0
<div class="input-group">
<input class="form-control" @onchange="() => Input(path)" />
</div>
@code{
string path;
private async Task Input(string path)
{
Console.log(path);
}
}
This code passes a null value to Input.
<div class="input-group">
<input class="form-control" @onchange="path => Input(path)" />
</div>
@code{
string path;
private async Task Input(string path)
{
Console.log(path);
}
}
This code gives "cannot convert from Microsoft.AspNetCore.Components.ChangeEventArgs to string"
<div class="input-group">
<input class="form-control" @onchange="path.ToString() => Input(path)" />
</div>
@code{
string path;
private async Task Input(string path)
{
Console.log(path);
}
}
This gives "Syntax error ',' expected".
Upvotes: 0
Views: 1563
Reputation: 133
This works:
<div class="input-group">
<input class="form-control" @onchange="@Input" />
</div>
private async Task Input(Microsoft.AspNetCore.Components.ChangeEventArgs patharg)
{
path = (string)patharg.Value;
Console.log(path);
}
Upvotes: 1