I am trying to call property for an event looking at MSDN and some stackoverflow posts for modal window(from here). But, I am getting an error in browser console saying Uncaught ReferenceError: OnClickCallback is not defined
. I'm working with Blazor Client.
My component
<div class="modal @ModalClass" tabindex="-1" role="dialog" style="display:@ModalDisplay">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">@Title</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close" @onclick="() => Close()">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<p>@ChildContent</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary" onclick="OnClickCallback">Continue</button>
<button type="button" class="btn btn-secondary" data-dismiss="modal" @onclick="() => Close()">Close</button>
</div>
</div>
</div>
</div>
@if (ShowBackdrop)
{
<div class="modal-backdrop fade show"></div>
}
@code {
public Guid Guid = Guid.NewGuid();
public string ModalDisplay = "none;";
public string ModalClass = "";
public bool ShowBackdrop = false;
[Parameter]
public string Title { get; set; }
[Parameter]
public RenderFragment ChildContent { get; set; }
[Parameter]
public EventCallback<MouseEventArgs> OnClickCallback { get; set; }
public void Open()
{
ModalDisplay = "block;";
ModalClass = "Show";
ShowBackdrop = true;
StateHasChanged();
}
public void Close()
{
ModalDisplay = "none";
ModalClass = "";
ShowBackdrop = false;
StateHasChanged();
}
}
Title
and ChildContent
works perfectly. But the OnClickCallback
event is throwing error.
My parent component where I'm trying to pass the event.
<BlazorApp1.Components.ModalComponent @ref="Modal" Title="Warning" OnClickCallback="@AddNewEducation">
<p>Do you wish to continue?</p>
</BlazorApp1.Components.ModalComponent>
@Code
private async Task AddNewEducation(MouseEventArgs e)
{
message = await Http.PostAsJsonAsync("api/Education", educationData);
if (message.IsSuccessStatusCode)
{
educationData.Description = string.Empty;
errorMessage = "Data saved successfully";
await ReloadData();
}
else
{
errorMessage = "Data saving failed";
}
}
I have gone through the official documentation and nothing worked.
Do anyone know whats the mistake in my code?