I have to bind a dropdown for country and after selecting the country state should be automatically populated in second dropdown list.
I have defined Model Class in following way.
public class Country
{
public string Code { get; set; }
public string Name { get; set; }
}
public class State
{
public string Code { get; set; }
public string Name { get; set; }
public Country CountryName { get; set; }
}
Q1. Is this the correct way to define Model Class?
After this I have a view
@Html.DropDownListFor(Model => Model.Country,new SelectList(ViewBag.Countries,"Code","Name"))
Q2. How and where should I write code to get states of selected country. (I have a method to get States when Country Code is passed as parameter)
public List<State> GetStates(string CountryCode)