@using Entity

<BootstrapInput @bind-value="@Model.FooName" DisplayText="Foo名称"></BootstrapInput>


<ValidateForm Model="@Model">
    <BootstrapInput @bind-value="@Model.Student.Name" DisplayText="名称"></BootstrapInput>
    <BootstrapInput @bind-value="@Model.Student.Fullname" DisplayText="全称"></BootstrapInput>
    <BootstrapInput @bind-value="@Model.Student.Address" DisplayText="地址"></BootstrapInput>
 </ValidateForm>

@code {
    [Parameter]
    public TestFoo? Model { get; set; }


    protected override async Task OnInitializedAsync()
    {
        await base.OnInitializedAsync();

        Model.Student = new TestStudent();

        if (Model.Id > 0)
        {
            // 模拟从数据库加载已有数据
            Model = await GetSutdent(Model.Id);
        }        
    }

    private async Task<TestFoo> GetSutdent(int id)
    {
        await Task.Delay(500); // 模拟异步操作
        TestFoo foo = new TestFoo();
        foo.Id = id;
        foo.FooName = "Existing FooName";

        foo.Student = new TestStudent()
        {
            Name = "Existing Name",
            Fullname = "Existing Fullname",
        };


        return foo;
    }
}
