Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
@code {
[Parameter] public Person Person { get; set; }
[Parameter] public string ButtonText { get; set; } = "Save Person";
[Parameter] public EventCallback OnValidSubmit { get; set; }
private List<Country> Countries = new List<Country>();
private List<State> States = new List<State>();
private int countryId = 0;
protected override async Task OnInitializedAsync()
{
if (Person.State != null)
{
countryId = Person.State.CountryId;
await LoadStates(countryId);
}
Countries = await http.GetJsonAsync<List<Country>>("api/countries");
}
private async Task CountryHasChanged(int value)
{
Person.StateId = 0;
countryId = value;
if (value == 0)
{
States.Clear();
}
else
{
await LoadStates(value);
}
}
private async Task LoadStates(int countryId)
{
States = await http.GetJsonAsync<List<State>>($"api/countries/{countryId}/states");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.