Gcobani Mkontwana

Gcobani Mkontwana

  • 955
  • 817
  • 1k

The button is not showing modal pop in blazor app

Oct 21 2024 10:25 AM

Hi Team

My app does not have any js error, but when i clicked the button its not launching modal form. What am missing?

@page "/main"
@using OperationManagerApp.Components;
@using OperationManagerApp.Models
@using Blazored.Modal
@using Blazored.Modal.Services

@inject IModalService Modal

<h3>Main Screen</h3>

<button @onclick="ShowAddOperationModal">Add Operation</button>

<OperationList Operations="operations" OnRemove="RemoveOperation" />

@code {
    private List<Operation> operations = new List<Operation>(); // Initialize with an empty list

    private async Task ShowAddOperationModal()
    {
        var modal = Modal.Show<AddOperationModal>("Add New Operation");
        var result = await modal.Result; 

        if (!result.Cancelled)
        {
            var newOperation = (Operation)result.Data; 
            operations.Add(newOperation); 
        }
    }

    private void RemoveOperation(int operationId)
    {
        var operationToRemove = operations.FirstOrDefault(op => op.OperationID == operationId);
        if (operationToRemove != null)
        {
            operations.Remove(operationToRemove); 
        }
    }
}

 


Answers (2)