相关疑难解决方法(0)

为什么 Blazor UI 组件在删除事件后没有更新?

为什么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)

c# asynchronous asp.net-core blazor blazor-server-side

7
推荐指数
1
解决办法
1365
查看次数

匿名方法 - 3 种不同方式 - 异步

不确定在标题中写什么,它们可能不都是匿名方法,但这里是:

假设我们有这个异步函数:

public async Task Delete(){  
  //something
}
Run Code Online (Sandbox Code Playgroud)

我正在使用 Blazor 服务器端,我对以下四种调用函数的方式感到好奇。假设它们在 div 标签内。

  1. onclick="@Delete"

  2. onclick="@(() => Delete(id))"

  3. onclick="@(async () => await Delete(id))"

  4. onclick="@(e => Delete(person.Id))

我不确定 1 是否是 Blazor 的新手,但它是否理解该方法是异步的?

如果需要传入参数,将使用 2 和 3,但我以前从未使用过 async-part,只在较旧的帖子中看到过。还需要说"async () =>"吗?

c# methods anonymous-function asp.net-core blazor

2
推荐指数
1
解决办法
905
查看次数