【发布时间】:2021-11-01 18:40:21
【问题描述】:
你好
我正在尝试在 blazor 服务器中制作可重用组件
一个列表框,我在其中传递一个 id(它用于填充自身,然后将用户选择的内容传回
我的想法是将ID传递给组件,从父级到子级,效果很好,但我只能从子级返回一个字符串,我想发回一个类对象,是否可能,我已经尝试了以下
父母
@using Microsoft.AspNetCore.Components.Web
@page "/"
@code {
private void IwasGivendatabackfromclient(HagClass x)
{
string text = x.parChildSet;
}
}
<h1>Hello, world!</h1>
Welcome to your new app.
<HagChild GiveMeDatFromPar="Balls of steel" OnEmployeeDeleted="IwasGivendatabackfromclient"></HagChild>
类
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Components.Web;
namespace Blazor_PH_Par_Child.Shared
{
public class HagClass
{
public string parSentMe { get; set; }
public string parChildSet { get; set; }
}
}
儿童
@code {
[Parameter]
public string GiveMeDatFromPar { get; set; }
[Parameter]
public EventCallback<object> OnEmployeeDeleted { get; set; }
HagClass x = new HagClass();
public void Delete_Click()
{
x.parChildSet = "test";
OnEmployeeDeleted.InvokeAsync(x);
}
}
<h3>HagChild</h3>
<button type="button" class="btn btn-danger m-1"
@onclick="Delete_Click">
Delete
</button>
<p>hello @GiveMeDatFromPar</p>
【问题讨论】:
标签: c# blazor parent-child blazor-server-side