ant-design-blazor / ant-design-blazor

🌈A rich set of enterprise-class UI components based on Ant Design and Blazor.
https://antblazor.com/
MIT License
5.83k stars 1.07k forks source link

ModalService doesn't work at blazor server mode #2781

Closed dswfort closed 2 years ago

dswfort commented 2 years ago

Describe the bug

Create a new Blazor Server project by Vusual Studio, copy the sample code from ant-design-blazor.gitee.io.

@inject ModalService _modalService

<Space>
    <SpaceItem>
        <Button OnClick="HandleInfo">Info</Button>
    </SpaceItem>
    <SpaceItem>
        <Button OnClick="HandleSuccess">Success</Button>
    </SpaceItem>
    <SpaceItem>
        <Button OnClick="HandleError">Error</Button>
    </SpaceItem>
    <SpaceItem>
        <Button OnClick="HandleWarning">Warning</Button>
    </SpaceItem>
</Space>
@code {
    private void HandleInfo()
    {
        RenderFragment content =@<div>
                <p>some messages...some messages...</p>
                <p>some messages...some messages...</p>
            </div>;
        _modalService.Info(new ConfirmOptions()
        {
            Title = "This is a notification message",
            Content = content
        });
    }

    private void HandleSuccess()
    {
        _modalService.Success(new ConfirmOptions()
        {
            Content = "some messages...some messages..."
        });
    }

    private void HandleError()
    {
        _modalService.Error(new ConfirmOptions()
        {
            Title = "This is an error message",
            Content = "some messages...some messages..."
        });
    }

    private void HandleWarning()
    {
        _modalService.Warning(new ConfirmOptions()
        {
            Title = "This is a warning message",
            Content = "some messages...some messages..."
        });
    }
}

Click button and no response...

Is ModalService couldn't work at blazor-server?

Further technical details

dswfort commented 2 years ago

BlazorApp1.zip Here is the demo~

ElderJames commented 2 years ago

Hi @dswfort , did you add the <AntContainer /> component in App.razor ?

image

zxyao145 commented 2 years ago

Hi @dswfort , did you add the <AntContainer /> component in App.razor ?

image

Yes, this may be the reason why ModalService is not working.

I download BlazorApp1.zip and it works fine when I add <AntContainer /> component. Please try adding <AntContainer />component to App.razor

image

dswfort commented 2 years ago

It works!

Sorry for reading document carelessly...