<1>html
范围:
<select id="fanwei" class="easyui-combobox" name="ff" data-options="width:120">
<option value="地市/区域">地市/区域</option>
<option value="省">省</option>
<option value="京津冀">京津冀</option>
</select>
名称:
<input type="text" style="width:100px;" id="sectionName" name="sectionName" class="easyui-combobox" data-options="" />
<2>js
<script>
$(function () {
//输入数据部分的城区名称
getName();
//切换‘范围’,显示对应的名称
$("#fanwei").combobox({
onSelect: function () {
getName();
}
});
});
function getName(fanwei, name) {
debugger;
$.ajax({
url: '@Url.Action("GetSection")',
dataType: "json",
type: "post",
data: {
id: $("#fanwei").combobox("getText")//"#fanwei"
},
success: function (result) {
$('#sectionName').combobox({//'#sectionName'
value: result[0].id,
data: result,
valueField: 'value',
textField: 'text'
});
}
});
}
</script>
<3>C#后台
/// <summary>
/// 地市/区域、省名称
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public string GetSection(string id)
{
EfHelper_AirQualityModel efAir = new EfHelper_AirQualityModel();
if (id == "地市/区域")
{
var sectionList = efAir.FindAll<T_Bas_CapAir>()
.Select(E => new { value = E.CityCode, text = E.CityName, id = E.CityCode }).Distinct().OrderBy(t => t.value)
.ToList<object>();
return sectionList.ToJson();
}
else if (id == "省")
{
var sectionList = efAir.FindAll<T_Bas_CapAir>()
.Select(E => new { value = E.ProvinceCode, text = E.ProvinceName, id = E.ProvinceCode }).Distinct().OrderBy(t => t.value)
.ToList<object>();
return sectionList.ToJson();
}
else if (id == "京津冀")
{
StringBuilder sectionList = new System.Text.StringBuilder();
sectionList.Append("[{\"value\":\"100001\",\"id\":\"100001\",\"text\":\"京津冀\"}]");
return sectionList.ToString();
}
else { return ""; }
}