![](/img/trans.png)
[英]What is a proper way to communicate from my website to the .NET (C#) and vice-versa?
[英]How to communicate between 3 nested components of blazor C# in two-way binding asp.net core (from parent to its grandchild vice versa)
我需要在后面的代碼中在 blazor 中的 3 個組件之間進行通信。
注意: Child-1 組件充當中間組件,它沒有任何 UI 元素
這是概念,我不知道如何在 parent 后面的代碼中調用 child-1 組件
示例: [在父組件中]
<button @onclick="callChildOne">Submit<button/>
void callChildOne(){
// i need to call child-1 here and pass the parameter status
// i need help in writing this code
}
我建立了這個案例,並提出了 blazor 的答案。 參考下面的例子
Child2.razor
@code{//some code}
兒童1.razor
//No UI, only methods in code behind
@code{
public void Show()
{
// TODO actual implementation for calling child 2 component
}
}
父.razor
<button @onclick="callChildOne">Submit<button/>
@*Add a @ref to the component *@
<Child1 @ref="childObj"></Child1 >
@code {
//Hold the reference to the component
private Child1 childObj;
// Call the public methods of the component
private void callChildOne() => childObj.Show();
}
這就是我在沒有任何服務的情況下與 3 個組件映射關系的方式。 我在這里從 Blazor的博客中閱讀了這個示例
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.