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
Main Screen
@code {
private List operations = new List(); // Initialize with an empty list
private async Task ShowAddOperationModal()
{
var modal = Modal.Show("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);
}
}
}
Jayraj ChhayaPosted Oct 22, 2024, 6:48 AM
The issue of the modal not displaying in your Blazor application could stem from a few common oversights. First, ensure that the
Blazored.Modalpackage is correctly installed and configured in your project. Check that you have included the necessary services in yourProgram.csfile:Next, confirm that you have added the
component in yourMainLayout.razoror the relevant layout file:Additionally, ensure that the
AddOperationModalcomponent is correctly implemented and that it inherits fromBlazoredModal. If the modal component is not set up properly, it may not render as expected.Lastly, verify that the
ShowAddOperationModalmethod is being called correctly when the button is clicked. You can add a simple debug statement or a breakpoint to ensure the method is executed. If all these aspects are correctly configured, the modal should display as intended.Gcobani MkontwanaPosted Oct 22, 2024, 8:04 AM
Hi
I did, on Program.cs i did configure this, but when i use Blazored on MainLayout.razor it throws an exception error.
//MainLayout.razor