【发布时间】:2019-01-25 15:10:45
【问题描述】:
我有一个父组件和一个子组件。在子组件中,我向父组件发出一个事件。但是我希望此 Action 为 async,因为我希望父组件在收到时执行 async 操作事件。我该怎么做?
儿童
@functions{
[Parameter] protected Action onclose { get; set; }
[Parameter] protected Action<bool> onsubmit { get; set; } //i want this handler to be async in the parent
string campaign;
public async Task OnSubmitAsync() {
var created = await this.service.CreateCampaignAsync(parameters);
Console.WriteLine("Result of creation:" + created.ToString());
this.onsubmit?.Invoke(created);
}
家长
<CampaignForm onclose="@(()=>OnModalClosed())" onsubmit="@(async(x)=>OnSubmit(x))"></CampaignForm>
@functions{
public async Task OnSubmit(bool value) {
//do some awaiting here
}
public void OnModalClose()=>....; //do something sync ;
}
【问题讨论】:
标签: c# asynchronous eventemitter blazor