CS0428 C# 无法将方法组转换为非委托类型"对象"。是否打算调用该方法?



我在Blazor中遇到了这个编译器错误("CS0428 C#无法将方法组转换为非委托类型的"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">

我在Razor视图中遇到了这个问题。

@line.GetExtraField<DateTime>("DeliveryDate").ToShortDateString()

然后我把它改成这个,它起作用了。

@(line.GetExtraField<DateTime>("DeliveryDate").ToShortDateString())

相关内容

  • 没有找到相关文章

最新更新