question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

EventCallback<T> Error cannot convert from 'method group' to 'EventCallback'

See original GitHub issue

Describe the bug

Using the following two components, the compiler emits an error in the Parent component in the OnSelect event parameter.

Error cannot convert from ‘method group’ to ‘EventCallback’

<Child Data="@Data" OnSelect="@OnSelect">
</Child>

Is this an issue or I am doing this wrong ?

To Reproduce

@*Parent.razor*@

@page "/Parent"

<div>
    <Child Data="@Data" OnSelect="@OnSelect">
    </Child>
</div>

@functions {
    List<Item> Data = new List<Item>();

    private void OnSelect(Item item)
    {        
    }
}
@*Child.razor*@

@typeparam TData

<div>
    @foreach (var item in Data)
    {
        <button onclick="@(() => OnSelect.InvokeAsync(item))"></button>
    }
</div>

@functions {
    [Parameter]
    public IEnumerable<TData> Data { get; set; }

    [Parameter]
    private EventCallback<TData> OnSelect { get; set; }
}
// Item.cs
public class Item
{
     public Item()
     {

     }
}

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
drinkwater99commented, May 9, 2019

Using async and Task does not change anything - the error remains.

The only way I am able to make it work is by doing the following in the Parent component event handler :

<Child Data="@Data" OnSelect2="@((Item item) => { OnSelect(item); })"></Child>

instead of :

<Child Data="@Data" OnSelect="@OnSelect">

Seems kind of strange to me that it would need to be done that way though.

0reactions
MichaelPetercommented, Jul 26, 2019

Hey I have Installed Preview 7 but I still get this error, shouldn’t this be fixed?

Read more comments on GitHub >

github_iconTop Results From Across the Web

cannot convert from 'method group' to 'EventCallback' - ...
I have a parent component and a child component with an event callback where I want it to pass back a type of...
Read more >
Cannot convert from method group to EventCallBack?
The code works fine when it the method is in the same file, but when I place it on another file it gives...
Read more >
cannot convert from 'method group' to 'EventCallback'
Hello, Can't understand what I'm doing wrong? Argument 2: cannot convert from 'method group' to 'EventCallback': Demo works.
Read more >
cannot convert from 'method group' to 'EventCallback'-blazor
The event handler expects a delegate EventCallback that can accept up to 1 parameter of type InputFileChangeEventArgs . Think of a delegate as...
Read more >
Cannot convert void to EventCallback in Blazor
I had created a simple method in a Razor page in my Blazor app ... me the error “Argument 2: cannot convert from...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found