$(document).ready(function () {
GetByJquery();
$("#s1").change(function () {
GetCity()
});
$("#s2").change(function () { GetStation() });
});
function GetByJquery() {
$("#s1").empty(); //清空省份SELECT控件
$.getJSON("resource/SendStation/GetProvinceList", function (data) {
$.each(data, function (i, item) {
$("<option></option>")
.val(item['Value'])
.text(item['Text'])
.appendTo($("#s1"));
});
GetCity();
});
}
function GetCity() {
$("#s2").empty(); //清空城市SELECT控件
var url = "resource/SendStation/GetCityList/?pid=" + $("#s1").val();
$.getJSON(url, function (data) {
$.each(data, function (i, item) {
$("<option></option>")
.val(item['Value'])
.text(item['Text'])
.appendTo($("#s2"));
});
GetStation();
});
}
function GetStation() {
$("#s3").empty(); //清空站点SELECT控件
var url = "resource/SendStation/GetStationList/?cid=" + $("#s2").val();
$.getJSON(url, function (data) {
$.each(data, function (i, item) {
$("<option></option>")
.val(item['Value'])
.text(item['Text'])
.appendTo($("#s3"));
});
});
}
/// <summary>
/// 获取所有[省份]数据
/// </summary>
public JsonResult GetProvinceList()
{
List<TrainStation> modellist = ResourceRule.GetProvinceList();
List<SelectListItem> items = new List<SelectListItem>();
foreach (var tem in modellist)
{
items.Add(new SelectListItem { Text = tem.TSProvinceName, Value = tem.TSProvinceId.ToString() });
}
return Json(items, JsonRequestBehavior.AllowGet);
}
public JsonResult GetCityList(int pid)
{
List<TrainStation> modellist = ResourceRule.GetCityList(pid);
List<SelectListItem> items = new List<SelectListItem>();
foreach (var tem in modellist)
{
items.Add(new SelectListItem { Text = tem.TSCityName, Value = tem.TSCityId.ToString() });
}
return Json(items, JsonRequestBehavior.AllowGet);
}
public JsonResult GetStationList(int cid)
{
List<TrainStation> modellist = ResourceRule.GetStationList(cid);
List<SelectListItem> items = new List<SelectListItem>();
foreach (var tem in modellist)
{
items.Add(new SelectListItem { Text = tem.TSName, Value = tem.TSId.ToString() });
}
return Json(items, JsonRequestBehavior.AllowGet);
}

浙公网安备 33010602011771号