I have a MVC3 project (using C#) and am using Razor and EntityFramework 4.1 and I'd like to accomplish the following:
1.Create a dropdown that displays provinces. Once you choose a province, it automatically populates a second dropdown that shows the cities under that province.
2.A second dropdown that shows the cities (as populated by the first dropdown), once the user chooses the city, it will automatically populate a table showing the suburbs under the city.
3.A table that contains a list of suburbs (based on the second dropdown).
Thanks in advance!
I've created my models,
public class Provinces{
[Key]public int ProvinceID {get; set;}
public string Province {get; set;}
public virtual ICollection<city> City {get;set;}}</city>
public class City{
[Key]public int CityID {get; set;}
public string City {get; set;}
public virtual ICollection<suburb> Suburb {get; set;}
public virtual Province Province {get; set;}}</suburb>
public class Suburb{
[Key]public int SuburbID {get; set;}
public string Suburb {get; set;}
public virtual City City {get; set;}}
A ViewModel to handle the dropdown
public class MyViewModel{
public string SelectedProvinceID {get; set;}
public string SelectedCityID {get; set;}
public IEnumerable<province> Province {get; set;}}</province>
A Controller
public class Suburbs : Controller{
MyEntities suburbsDB = new MyEntities();
public ActionResult Create(){
ViewBag.Province = suburbsDB.Province.OrderBy(prov => prov.Province).ToList();
var suburbDetails = new Suburb();
return View(suburbDetails);}
I'm quite new to EntityFramework, Json, and Razor and I'm having a problem on how will I create the view.
How can I refresh the table based on the value of the Suburb dropdown?