(Blazor) 子组件不渲染

(Blazor ) Child Component not rendering

我使用 Syncfusion 创建了一个 Dialog 组件,我试图从父组件调用它,但它没有呈现。

这是我的父组件,我在我的子组件 (ModalAcceptCancel) 中使用 @ref,因此当我单击删除按钮(在我的网格中)时,我能够调用名为 OpenDialog 的方法来呈现或显示我的模式.

@using App.Dtos
@using App.Data
@using Syncfusion.Blazor.Buttons
@inject NavigationManager NavigationManager

//This is my child component
<ModalAcceptCancel @ref="Modal"/>
//
<SfGrid @ref="SfGridProfesores" DataSource="@DsProfesores" AllowPaging="true">
    <GridColumns>
        <GridColumn Field=@nameof(ProfesorDto.Id) HeaderText="Identificador" TextAlign="TextAlign.Right" Width="120">
        </GridColumn>
        <GridColumn Field=@nameof(ProfesorDto.Nombres) HeaderText="Nombre" Width="200"></GridColumn>
        <GridColumn Field=@nameof(ProfesorDto.CorreoElectronico) HeaderText="Correo Electrónico" Width="150"></GridColumn>
        <GridColumn HeaderText="Acciones" TextAlign="TextAlign.Center" Width="120">
            <Template>
                @{
                    var profesor = (context as ProfesorDto);             
                    <SfButton @onclick="@(() => NavigationManager.NavigateTo("Profesor/"+profesor.Id))" CssClass="e-info">Editar</SfButton>
                    <SfButton CssClass="e-danger" @onclick="(() => DeleteProfesor(profesor.Id))">Borrar</SfButton>                                  
                }
            </Template>
        </GridColumn>
    </GridColumns>
</SfGrid>

@code {
    [Parameter]
    public IReadOnlyList<ProfesorDto> DsProfesores { get; set; }

    [Inject]
    public IProfesorService ProfesorService { get; set; }

    SfGrid<ProfesorDto> SfGridProfesores;

    ModalAcceptCancel Modal; 

    //Here i try to open my Modal (ChildComponent)
    private void DeleteProfesor(int id)
    {
        Modal.OpenDialog();
        //ProfesorService.BorraProfesor(id);
       // SfGridProfesores.Refresh();
    }
}

这是我的子组件的代码。我的 Syncfusion 对话框可见性绑定到“可见 属性”,当调用 OpenDialog 方法时 属性 更改为 true,它应该显示我的模态。

@using Syncfusion.Blazor.Popups
@using Syncfusion.Blazor.Buttons


<SfDialog Width="500px" ShowCloseIcon="true" CloseOnEscape="true" @bind-Visible="@IsVisible">
    <DialogTemplates>
        <Header> Atención </Header>
        <Content> ¿Estás seguro que deseas eliminar este elemento? </Content>
        <FooterTemplate>
            <SfButton CssClass="e-primary e-flat" @onclick="@CloseDialog">
                Aceptar
            </SfButton>
            <SfButton CssClass="e-flat" @onclick="@CloseDialog">
                Cancelar
            </SfButton>
        </FooterTemplate>
    </DialogTemplates>
</SfDialog>

@code {
    private bool IsVisible { get; set; } = false;

    public void OpenDialog()
    {
        this.IsVisible = true;
    }

    public void CloseDialog()
    {
        this.IsVisible = false;
    }
}

¿我做错了什么? ¿ 这样做有更好的做法吗?

我真的是开发新手。对不起我的英语。

这是应该调用模态的代码,对吧?

 @onclick="(() => BorrarProfesor(profesor.Id))"

您需要此代码:

@onclick="(() => DeleteProfesor(profesor.Id))"

调用 DeleteProfesor 方法,将教授 ID 传递给它,从中执行 Modal.OpenDialog();...

定义为 DeleteProfesor 如下:

//Here i try to open my Modal (ChildComponent)
    private async void DeleteProfesor(int id)
    {
        Modal.OpenDialog();
        //ProfesorService.BorraProfesor(id);
       // SfGridProfesores.Refresh();
    }

希望对您有所帮助!如果您遇到困难,请告诉我

来自 Syncfusion 支持的问候,

我们已经验证了您报告的查询和共享代码块。 IsVisible 属性 是从另一个 razor 页面调用的,因此 属性 更改不受 SfDialog 的影响,因此不会显示。我们建议您调用 属性 更新旁边的 StateHasChanged() 来解决所报告的问题。我们还准备了一个样本,试图满足您的要求。

样本:https://www.syncfusion.com/downloads/support/directtrac/general/ze/SFDIAL~22087980339

如果解决方案有帮助,请告诉我们,

此致,

因陀罗吉