@page "/"
@using System.ComponentModel.DataAnnotations;
<PageTitle>@PageTitle</PageTitle>
<h1>Hello, world!</h1>
Welcome to your new app.
<EditForm Model="ParentModel" OnValidSubmit="ValidFormSubmitted" OnInvalidSubmit="InvalidFormSubmitted">
<ObjectGraphDataAnnotationsValidator />
<ValidationSummary />
<div>
<InputText @bind-Value="ParentModel.Name" />
<ValidationMessage For="@(() => ParentModel.Name)" />
</div>
<div>
<InputTextArea @bind-Value="ParentModel.Description" />
</div>
<div>
<AddressComponent ChildAddress="ParentModel.SimpleAddress" ChildSimpleString="@ParentModel.JustAString" />
</div>
<input type="submit" class="btn btn-primary" value="Save Things" />
</EditForm>
<div>@StatusMessage</div>
@code
{
public class SimpleModel
{
[Required]
public string? Name { get; set; }
public string? Description { get; set; }
[Required]
public string? JustAString { get; set; }
[ValidateComplexType]
public Address? SimpleAddress { get; set; } = new Address();
}
public class Address
{
public string? Street { get; set; }
[Required]
public string City { get; set; } = string.Empty;
}
[Parameter]
public string? PageTitle { get; set; } = "IMA TITLE";
public SimpleModel ParentModel { get; set; } = new SimpleModel();
public string StatusMessage { get; set; } = "nothing has happened yet";
protected override async Task OnInitializedAsync()
{
await base.OnInitializedAsync();
ParentModel = new SimpleModel()
{
};
}
private async Task ValidFormSubmitted(EditContext editContext)
{
StatusMessage = "yay";
}
private async Task InvalidFormSubmitted(EditContext editContext)
{
StatusMessage = "boo";
}
private async Task OnMyAddressThingChanged(Address addressThing)
{
StatusMessage = "address thing changed";
}
}