Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Beginner Blazor issue: cannot convert from 'method group' to 'EventCallback'

I am creating my first Blazor app and I have two components named child and parent:

child:

<div class="alert alert-primary" role="alert">
    @Title
</div>

<div class="alert alert-primary" role="alert">
    @ChildContent
</div>

<button type="button" class="btn btn-primary" @onclick="onClickMethod">Primary</button>


@code {
    [Parameter]
    public string Title { get; set; }

    [Parameter]
    public RenderFragment ChildContent { get; set; }

    [Parameter]
    public EventCallback onClickMethod { get; set; }
}

Parent:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

@page "/childcomp"

<h3>ParentComponent</h3>
<BlazingShop.Pages.Components.ChildComponent OnClickMethod="@ShowMessage"
                                             Title="This title is from parent"> This is between component of the parent</BlazingShop.Pages.Components.ChildComponent>

<p><b>@messageText</b></p>

@code {
    private string messageText;
    private void ShowMessage()
    {
        messageText = "Blazing Text from Parent";
    }

}

In the Parent section, the @ShowMessage" is red and I see the error. I am following an online tutorial, and this is happening only on my side. What how I fix this issue?

Thanks

>Solution :

You have a casing issue on your parent.

In your child component, the EventCallback property has a name of onClickMethod. On the parent you are using OnClickMethod. These properties are case sensitive.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading