A cascading dropdown for loading countries and associated states and local governments.
stable release version:
Nuget package downloads:
C#, .Net6.0, .NetStandard2.1 ,
First, install NuGet. Then, install CountryRegion from the package manager console:
NuGet \Install - Package CountryRegion - Version 1.0 .10
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
Or from the .NET CLI as:
dotnet add package CountryRegion -- version 1.0 .10
Finally, import into the file:
Get all countries
Get all states
Get all local governments
Get a country
Get a state
Get a local government
await Region . Countries ( ) ;
Type
Task<IEnumerable<Response?>>
await Region . GetStates ( countryId ) ;
Parameter
Type
Description
countryId
int
Required . The id of the country to get the states associated with it
Type
Task<IEnumerable<Response?>>
await Region . GetLGAs ( countryId , stateId ) ;
Parameters
Type
Description
countryId,
int
Required . The id of the country to get the local governments from
stateId
int
Required . The id of the state to get the local governments from
Type
Task<IEnumerable<Response?>>
await Region . GetCountry ( countryId ) ;
Parameter
Type
Description
countryId
int
Required . The id of the country to get
await Region . GetState ( countryId , stateId ) ;
Parameters
Type
Description
countryId,
int
Required . The id of the country to get a state from
stateId
int
Required . The id of the state to get
await Region . GetLGA ( stateId , lgaId ) ;
Parameters
Type
Description
stateId
int
Required . The id of the state to get local government from
lgaId
int?
Required . The name of the local government in that state
GetState Extension Method
await Region . GetState ( List < dynamic > objs , countryId , stateId ) ;
Retrieves a specific state based on the provided parameters.
Parameters
Type
Description
objs
List<dynamic>
Required . A list of objects representing the states.
countryId
int
Required . The ID of the country to retrieve the state from.
stateId
int
Required . The ID of the state to retrieve.
await Region . GetLGA ( List < dynamic > objs , stateId , lgaId ) ;
Retrieves a specific Local Government Area (LGA) based on the provided parameters.
Parameters
Type
Description
objs
List<dynamic>
Required . A list of objects representing the LGAs.
stateId
int
Required . The ID of the state to retrieve the LGA from.
lgaId
int?
The ID of the specific LGA to retrieve (optional). If not provided, its assumed the state has no LGA
Thanks to all Contributors
Maintainers:
Contributions are always welcome!
See contributing.md for ways to get started.
Please adhere to this project's code of conduct.