how call api in FormEdit for checkbox?

sblb 1,166 Reputation points
2022-09-28T12:20:09.997+00:00

Hi, I try to put a checkbox in my application which call an api, thanks to @AgaveJoe .

I've to put await http.GetFromJsonAsync<Developer>($"api/developer/SelectEcoById/{id}"); to invoke SelectedEcoById on Task OnParametersSetAsync()
how should I proceed?

<FormEdit ButtonText="Update" dev="dev"  OnValidSubmit="@EditDeveloper" />  
  
@code {  
  
    [Parameter] public int developerId { get; set; }  
    [Parameter] public int id { get; set; }  
    Developer dev = new Developer();           
  
    protected async override Task OnParametersSetAsync()  
    {  
        dev = await http.GetFromJsonAsync<Developer>($"api/developer/{developerId}");  
           
    }  
  
    async Task EditDeveloper()  
    {  
  
        await http.PutAsJsonAsync("api/developer", dev);  
        await js.InvokeVoidAsync("alert", $"Updated Successfully!");  
        uriHelper.NavigateTo("developer");          
    }      
}  

FormEdit.razor

<EditForm Model="@dev" OnValidSubmit="@OnValidSubmit">  
    <DataAnnotationsValidator />  
  
 <input type="checkbox" checked="@isChecked" oninput="CheckboxChanged">  
  
</EditForm>  
  
@code {  
    [Parameter] public Developer dev { get; set; }  
    [Parameter] public EventCallback OnValidSubmit { get; set; }  
    
    Developer[] developers { get; set; }  
  
    [Parameter] public bool IsChecked { get; set; } = false;  
    private bool isChecked;  
  
    protected override void OnParametersSet()  
    {  
        isChecked = this.IsChecked;  
    }  
  
    private void CheckboxChanged(ChangeEventArgs e)  
    {  
        // get the checkbox state  
       // var value = e.Value;  
           dev.ECOSelected = true;  
    }  
Blazor
Blazor
A free and open-source web framework that enables developers to create web apps using C# and HTML being developed by Microsoft.
1,428 questions
{count} votes