Skip to content

Instantly share code, notes, and snippets.

@gavilanch
Created December 3, 2019 20:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gavilanch/6915c2a9e5de457d45127dd80911b5b8 to your computer and use it in GitHub Desktop.
Save gavilanch/6915c2a9e5de457d45127dd80911b5b8 to your computer and use it in GitHub Desktop.
@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