【发布时间】:2021-02-16 19:46:21
【问题描述】:
我正在尝试将子组件包含到父组件中
但是子组件不工作
下面是代码
==================== parent component razor ====================
<InfoDialog @ref="infoDialog"></InfoDialog>
==================== parent component code behind ====================
public InfoDialog infoDialog { get; set; }
public async Task AddToDB()
{
infoDialog.Show("success", "request complete!");
}
==================== child component razor ====================
<MatDialog @bind-IsOpen="@IsShow">
<MatDialogTitle>@Title</MatDialogTitle>
<MatDialogContent>
<p>@Description</p>
</MatDialogContent>
<MatDialogActions>
<MatButton OnClick="@Close">OK</MatButton>
</MatDialogActions>
</MatDialog>
==================== child component code behind ====================
public partial class InfoDialog
{
public bool IsShow { get; set; }
public string Title { get; set; }
public string Description { get; set; }
public void Show(string _title, string _Description)
{
IsShow = true;
Title = _title;
Description = _Description;
}
public void Close()
{
IsShow = false;
}
}
当我调用'AddToDB'函数时,我调用了子组件的show函数,但是子组件没有被渲染。谁能帮帮我?
对不起我的英语不好
【问题讨论】:
-
我添加了 this.StateHasChanged();在 infoDialog.Show() 下。但现在也醒了
标签: asp.net-core .net-core parent-child blazor code-behind