I am trying to execute an asynchronous method when pressing a button. The code compiles without issue, but when the button is clicked the method is never called. I have used all the google fu i have at my disposal to no avail. Am I doing something wrong syntactically? Did i forget to import something or am i misunderstanding how this works?
@foreach (Data.Course cor in CourseList)
{
/...
<button class="btn btn-outline-primary" @onclick="@(async () => await EnrollCourse(cor.CourseId))">
Enroll
</button>
}
@functions{
private async Task EnrollCourse(int corid)
{
var authState = await AuthenticationStateProvider.GetAuthenticationStateAsync();
string userid = authState.User.Identity.Name;
await _db.EnrollCourse(corid, userid);
NavigationManager.NavigateTo($"/course/{corid}");
}
}
@functionsstill work? What Blazor version are you using?