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:
@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.