While working on a Blazor
project. The razor page was functioning correctly until I updated MudBlazor to version 8
. At first, code was working as expected, but when I updated the version, I am having CS1666
and CS0123
error now. What am I missing on the updates?
My Code :
<EditForm Model="accountrole" OnValidSubmit="OnValidSubmit">
<DataAnno2tationsValidator />
<MudDialog>
<DialogContent>
@if (accountrole.AccountRoleID > -1)
{
<MudAutocomplete T=Account
Label="Account"
@bind-Value="selectedAccount"
SearchFunc=SearchAcc
Variant="Variant.Outlined"
Clearable="true"
ToStringFunc="@(e=> e==null?null : $"{e.AccountName}")" />
<MudAutocomplete Class="mt-3"
T=Role
Label="Account"
@bind-Value="selectedRole"
SearchFunc=SearchRole
Variant="Variant.Outlined"
Clearable="true"
ToStringFunc="@(e=> e is null ? null : $"{e.Title}")" />
}
</DialogContent>
<DialogActions>
<MudButton OnClick="Cancel">Cancel</MudButton>
<MudButton ButtonType="ButtonType.Submit"
Variant="Variant.Filled"
Color="MudBlazor.Color.Primary">
@(mode == "edit" ? "Update" : "Save")
</MudButton>
</DialogActions>
</MudDialog>
</EditForm>
@code {
bool success;
[Parameter] public AccountRole accountrole { get; set; } = new AccountRole();
[Parameter] public List<Account> accountList { get; set; } = new List<Account>();
[Parameter] public List<Role> roleList { get; set; } = new List<Role>();
[Parameter] public string? mode { get; set; }
[CascadingParameter] IMudDialogInstance? MudDialog { get; set; }
void Submit() => MudDialog?.Close(DialogResult.Ok(true));
void Cancel() => MudDialog?.Cancel();
private async Task OnValidSubmit(EditContext context)
{
success = true;
await addAccountRole();
}
// AUTOCOMPLETE FOR Account
//public Account account { get; set; } = new Account();
private Account? selectedAccount;
private async Task<IEnumerable<Account>> SearchAcc(string value)
{
StateHasChanged();
await Task.Delay(5);
await Task.Yield();
return (string.IsNullOrEmpty(value)) ? accountList : accountList.Where(x => x.AccountName.Contains(value, StringComparison.InvariantCultureIgnoreCase));
}
// AUTOCOMPLETE FOR Role
//public Role role { get; set; } = new Role();
private Role? selectedRole;
private async Task<IEnumerable<Role>> SearchRole(string value)
{
StateHasChanged();
await Task.Delay(5);
return (string.IsNullOrEmpty(value)) ? roleList : roleList.Where(x => x.Title.Contains(value, StringComparison.InvariantCultureIgnoreCase));
}
}
I just figured out the answer to the problem. I just added CancellationToken argument to the functions:
From:
private async Task<IEnumerable<Account>> SearchAcc(string value) {...}
private async Task<IEnumerable<Role>> SearchRole(string value) {...}
To:
private async Task<IEnumerable<Account>> SearchAcc(string value, CancellationToken token) {...}
private async Task<IEnumerable<Role>> SearchRole(string value, CancellationToken token) {...}