Click here to Skip to main content
14,695,620 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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(){ 
//For Province dropdown
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?
Posted
Updated 2-May-11 4:52am
v2

1 solution

u can use this control

just download dll and use...here is link

http://www.obout.com/combobox/aspnet_master_detail_cascading.aspx[^]
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900