Skip to content

Cannot convert from 'method group' to 'Event Callback' Blazor #26806

@scott-david-walker

Description

@scott-david-walker

Creating a component when I want to have it as generic as possible but if I try to use EventCallback with a type of T then I get a Cannot convert from 'method group' to 'Event Callback' error

`

TestComponent


@typeparam T
@foreach (var x in TableData)
{
<a @OnClick="@(()=>DeleteCallback.InvokeAsync(x))">
}

@code {

[Parameter]
public List<T> TableData { get; set; }

[Parameter]
public EventCallback<T> DeleteCallback { get; set; }

}`

`

@code
{
public class Item
{
public Guid Id { get; set; }
}

public List<Item> example = new List<Item>
{
    new Item
    {
        Id = Guid.NewGuid()
    }
};

public async Task OnDelete(Item item)
{
}

}`

I've created a basic repo here - https://github.com/scott-david-walker/EventCallbackError

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-blazorIncludes: Blazor, Razor Components

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions