Skip to content

[Bug] modal close event is causing codebehind fire start up cycle again and viewmodel to construct multi time #586

@paulhaggo1983

Description

@paulhaggo1983

Describe the bug
When I load the modal, the events you would expect fire. such as code behind SetParametersAsync, OnInitialized ,OnParametersSet and the linked viewmodel to fire the construct

When i close the modal, it fired them all again, have you even seen this issue please ?, we have just upgraded to .net8 Blazor Server

I call the modal with

var returnFilterData =
    await _dialogManager.OpenInterfaceAsModalAsync<IGridFilterEditor_View, GridFilterEditor_Output>("", inputs);

public async Task<O> OpenInterfaceAsModalAsync<T, O>(string title = null, IEnumerable<KeyValuePair<string, object>> inputs = null)
{
    var concreteImplementation = _serviceProvider.GetService<T>();
    var concreteType = concreteImplementation.GetType();
    return await OpenAsModalAsync<O>(concreteType, title, inputs);
}    
 public async Task<O> OpenAsModalAsync<O>(Type viewFragmentType, string title = null, IEnumerable<KeyValuePair<string, object>> inputs = null)
{
    if (inputs == null)
        inputs = new List<KeyValuePair<string, object>>();

    // Params
    var mp = new ModalParameters();
    mp.Add("ViewFragmentType", viewFragmentType);
    mp.Add("Inputs", inputs);

    // Options
    var mo = new ModalOptions { DisableBackgroundCancel = true, Position = ModalPosition.Middle , UseCustomLayout = true };

    // Open the form
    var modalForm = _modalService.Show<ModalHost_View>(title, mp, mo);
    var modalResult = await modalForm.Result;

    if (!(modalResult?.Confirmed ?? false)) return default;
    if (modalResult.Data == null) return default;
    if (modalResult.Data is not O) return default;

    return (O)modalResult.Data;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugSomething isn't workingTriageIssue needs to be triaged

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions