gpt4 book ai didi

asp.net-core - CS0428 C# 无法将方法组转换为非委托(delegate)类型 'object'。您是否打算调用该方法?

转载 作者:行者123 更新时间:2023-12-05 02:06:22 33 4
gpt4 key购买 nike

我在 Blazor 中遇到此编译器错误(“CS0428 C# 无法将方法组转换为非委托(delegate)类型‘object’。您是否打算调用该方法?”),我真的不知道如何修复它或使用哪条路径采取。该错误发生在下拉列表的两个 onchange 事件上。请帮忙!

<select class="form-control" onchange="**@ReportingYearClicked**" style="width: 95px">
<option value="">-- Select Reporting Year --</option>
@foreach (var year in @yearlist)
{
<option value="@year">@year</option>
}
</select>

<select class="form-control" onchange="**@ClientClicked**" style="width: 600px">
<option value="">-- Select Client --</option>
@if (ReportingYear == "ALL")
{
@if (client != null)
{
@foreach (var client in @client)
{
<option value="@client.ClientUno">@client.ClientUno &nbsp; @client.ClientName</option>
}
}
}
else
{
@if (clientListDto != null)
{
@foreach (var client in @clientListDto)
{
<option value="@client.ClientUno">@client.ClientUno &nbsp; @client.ClientName</option>
}
}
}
</select>

@Code
{
protected override async Task OnInitializedAsync()
{
DateTime now = DateTime.Today;
currentyear = now.ToString("yyyy");
YearList(currentyear);
client = await Http.GetJsonAsync<List<ClientDto>>("http://XXXXXXX/api/clients");
}

protected async void ReportingYearClicked(ChangeEventArgs clientEvent)
{
client.Clear();
clientListDto.Clear();
clientListDto = await
Http.GetJsonAsync<List<ClientListDto>>"api/clientListReportingYear="+
ReportingYear);

this.StateHasChanged();
}

void ClientClicked(ChangeEventArgs clientEvent)
{
ReportingYear = clientEvent.Value.ToString();
this.StateHasChanged();
}
}

最佳答案

您必须将调用 onchange 事件的代码更改为@onchange:

<select class="form-control" @onchange="@ReportingYearClicked" style="width: 95px">

关于asp.net-core - CS0428 C# 无法将方法组转换为非委托(delegate)类型 'object'。您是否打算调用该方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62803370/

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