开拓者不刷新组件

[Blazor客户端托管] 我有一个简单的表,可以很好地从api加载数据...现在,我需要应用过滤器并重新加载表以显示新数据/列表;

剃刀

@inherits PersonBase;

<table class="table">
    <thead>
        <tr>
            <th>Id</th>
            <th>Name</th>

        </tr>
    </thead>
    <tbody>
        @foreach (var person in @ListPeople)
        {
        <tr>
            <td>@person.Id</td>
            <td>@person.Name</td>
        </tr>
        }
    </tbody>
</table>

PersonBase.cs

protected async Task LoadPeople(string search)
{
    try
    {
        var httpResponse = await Http.GetAsync($"api/people/list/{search}");

        if (httpResponse.IsSuccessStatusCode)
        {
            var responseString = await httpResponse.Content.ReadAsStringAsync();

            ListPeople = JsonSerializer.Deserialize<List<Person>>(responseString,
            new JsonSerializerOptions()
            {
                PropertyNameCaseInsensitive = true
            });

            Itens = ListPeople;
            Console.WriteLine("Count=> " + ListPeople.Count); // returning all 3 objects 
        }
    }
}

PersonController.cs

        [HttpGet("lista/{search}")]
        public async Task<ActionResult<List<Person>>> GetByAll(string search)
        {
            try
            {
                if (string.IsNullOrEmpty(search))
                {
//--Loading all work fine..
                }
                else
                {
                    return await _context.Person
                        .AsNoTracking()
                        .Where(n => n.Name.ToLower().Contains(search.ToLower())
                        .Take(3)
                        .ToListAsync();
                }
            }
        }

Api method have a filter that working fine too...Apllying filter e.g search.Equals("Item 1"),

Console.WriteLine("Count=> " + ListPeople.Count); // returning 1 object filtered 

但是表不会在表中加载新数据。我尝试以下所有内容,但不成功。我现在可以尝试什么?先谢谢了。

我尝试没有成功:

protected override async Task OnParametersSetAsync()
{
    if (!string.IsNullOrEmpty(search))
    {
        await LoadPeople(search);
    }

}

    protected async Task LoadPeople(string search)
    {
....
StateHasChanged();    
}

enter image description here enter image description here

评论