i have two component. The first component includes list of model and the second component contains modal form I want to click on the model when inside the first component In the second component, open modal and edit the model how to call show function in child component from parent component
<ChildComponent />
<button onClick="@ShowModal">show modal</button>
@code{
ChildComponent child;
void ShowModal(){
child.Show();
}
}
i'm used @using but this code has error :
the type or namespace name ChildComponent coud not be found
First you need to capture a reference of your child component:
<ChildComponent @ref="child" />
Then you can use this reference to call the child's component methods as you do in your code.
<button onClick="@ShowModal">show modal</button>
@code{
ChildComponent child;
void ShowModal(){
child.Show();
}
}
The namespace of your component need to be added by a using either in the page or in _Imports.razor. If your component is in the sub folder Components/ChildComponent.razor then its namespace is {YourAppNameSpace}.Components
@using MyBlazorApp.Components