I have a Blazor app with a MainLayout page, which has a @Body to load the actual page content.
In my case Index.razor is loaded inside the MainLayout page.
Is there a way to call a method from the child page (Index.razor) that lives in the parent page; MainLayout.razor?
Example:
MainLayout.razor
<div class="content">
<ul class="menu">
<li>menu item 1</li>
</ul>
@Body
</div>
@code
{
public async Task Test()
{
await JsRuntime.InvokeAsync<object>("console.log", "test parent");
}
}
Index.razor
<h1>This is the index page</h1>
<button @onclick="(async () => await btn_clicked())">Call parent method</button>
@code
{
// Call method in MainLayout
public async Task btn_clicked()
{
await parent.Test();
}
}
@onclick=btn_clicked- Neville Nazerane