为什么Blazor UI在删除事件后不更新:
我的组件:
<table class="table table-striped">
<thead>
<tr>
<th>Id</th>
<th>Name</th>
<th>Example</th>
<th></th>
</tr>
</thead>
<tbody>
@foreach (var trainingTechnique in TrainingTechniques) {
<tr>
<td>@trainingTechnique.Id</td>
<td>@trainingTechnique.Name</td>
<td>@trainingTechnique.Example</td>
<td>
<button type="button"
class="btn btn-danger"
@onclick="@(async () => await DeleteTechnique(trainingTechnique.Id))">
Delete
</button>
</td>
</tr>
}
</tbody>
</table>
Run Code Online (Sandbox Code Playgroud)
我后面的组件代码:
public class TrainingTechniqueViewPageBase : ComponentBase
{
public List<TrainingTechniqueView> TrainingTechniques { get; set; }
[Inject]
public ITrainingTechniqueConsumer TrainingTechniqueConsumer { get; set; }
protected TrainingTechniqueForm TrainingTechniqueForm { get; set; }
protected override async Task OnInitializedAsync()
{
TrainingTechniques …Run Code Online (Sandbox Code Playgroud) 不确定在标题中写什么,它们可能不都是匿名方法,但这里是:
假设我们有这个异步函数:
public async Task Delete(){
//something
}
Run Code Online (Sandbox Code Playgroud)
我正在使用 Blazor 服务器端,我对以下四种调用函数的方式感到好奇。假设它们在 div 标签内。
onclick="@Delete"
onclick="@(() => Delete(id))"
onclick="@(async () => await Delete(id))"
onclick="@(e => Delete(person.Id))
我不确定 1 是否是 Blazor 的新手,但它是否理解该方法是异步的?
如果需要传入参数,将使用 2 和 3,但我以前从未使用过 async-part,只在较旧的帖子中看到过。还需要说"async () =>"吗?