gpt4 book ai didi

c# - 第二次点击后页面刷新?

转载 作者:太空宇宙 更新时间:2023-11-03 22:29:59 25 4
gpt4 key购买 nike

我有以下 blazor 页面来显示来自数据库的过滤结果页面。

@inject ViewModels.MyViewModel VM
<input id="search" type="text" @bind="search" />
<input id="search" type="button" value="Go" @onclick="SearchChanged" />
<p>Current count: @currentCount</p>
@code {
string search = "";
int currentCount = 0;
IEnumerable<MyDto> dtos;

async void SearchChanged() {
currentCount++;
Console.WriteLine($"VM.Ric: {ric}"); // Correct values will be printed
dtos = GetList(search);
}
}
@if (dtos == null)
{
<p><em>Please enter the ...</em></p>
}
else
{
<table class="table">
<thead>
<tr>
<th>ID</th>
</tr>
</thead>
<tbody>
@foreach (var ca in dtos)
{
<tr>
<td>@ca.ID</td>
</tr>
}
</tbody>
</table>
}

但是,我需要点击按钮两次(在输入 a 之后)才能看到结果。例如,输入“ABC”后点击按钮不会刷新屏幕。再次单击将显示正确的值。

最佳答案

你应该在

中使用 Task而不是 void
async void SearchChanged()

使用这个:async Task SearchChanged()

关于c# - 第二次点击后页面刷新?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58384646/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com