[英]EventCallback<dynamic> throws RuntimeBinderException
Using the default template I modified the Counter:使用默认模板我修改了计数器:
@code {
private int currentCount = 0;
private async void IncrementCount()
{
currentCount++;
await UpdateCallback.InvokeAsync(new { Counter = currentCount });
}
[Parameter] public EventCallback<dynamic> UpdateCallback { get; set; }
}
And I am using it like this:我正在这样使用它:
<Counter UpdateCallback="(d)=>MyCallback(d,42)"></Counter>
@code {
public void MyCallback(dynamic val, int number)
{
}
}
This leads to这将导致
Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: 'Cannot implicitly convert type 'void' to 'object''
Microsoft.CSharp.RuntimeBinder.RuntimeBinderException:'无法将类型'void'隐式转换为'object''
If I pass around a Tuple<dynamic>
it works.如果我传递一个
Tuple<dynamic>
它可以工作。
Why is that?这是为什么?
You invoked using InvokeAsync so it is expecting a method which will return task not void.您使用 InvokeAsync 进行了调用,因此它需要一个返回任务不无效的方法。 Use this where you used your Counter component, i think that will solve your problem.
在您使用 Counter 组件的地方使用它,我认为这将解决您的问题。
<Counter UpdateCallback="async (d)=> await MyCallback(d,42)"></Counter>
@code {
public async Task MyCallback(dynamic val, int number)
{
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.