后台代码,获取数据如下:
///定义两个下拉框:2 /// 获取省份 3 /// 4 public JsonResult GetProvincelist() 5 { 6 return Json(db.Province.ToList(),JsonRequestBehavior.AllowGet); 7 } 8 ///9 /// 获取城市10 /// 11 /// 12 ///13 public JsonResult GetCitylist(int pid)14 {15 List list=db.City.Where(c => c.Province.PID == pid).ToList();16 List item = new List ();17 foreach (var City in list)18 {19 item.Add(new SelectListItem { Text = City.CityName, Value = City.CID.ToString() });20 }21 return Json(item, JsonRequestBehavior.AllowGet);22 }
1 省份:2 5 6 市:7使用jquery获取控制器里返回的值加载到下拉框中: