Created
December 3, 2019 20:56
-
-
Save gavilanch/6915c2a9e5de457d45127dd80911b5b8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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