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WFBY0Z6VL8uMYSvgZ0AJlhPW4g+5UtuRZHyKTOh67+AnQAeYnYqBLy64oNEbgnh9tNyCxo3ozEjLTPBM+gAbCS+n33cjGRGWmoIj0HtBPDBPpMZe1JN9FyRPgTbnQAu2LUzu7DUvhQaXSCHNWuD86vDGhKeBQLgglk7L1bVNh45cdbmCw7OrQyolkTT3n7V8uV78LQFAA9Jrz4WKt38SadAsVgF18YDmGDbyd24r6jvjb1n3PJKbv8O7noDMMF+Fgg376R5cY0/aX81YeGNmXrGLd/eeo47SWCPwjze2dPUVBdvp7FbZgY7AVywzmS+5OafsiyuCaYcvXJrt8zUM269AHYCmGAf7/zs+GmLJ/Ba6eZPOl7Jrb1vYLsTwAbreGfrkRNnbD5qYNYnmvEIFO7X056qu/AMOgAPLDsbswtL7cuhEW1gSLMqnl8ZVPvhjmEAF+x99rfn2U1hqSE0ZoQ7NwBssK8+jrzFdXoRKVxoyokU8BZXAB9sO0+cJZbW6YU1pFlFaj/SrKJbz8FOAA9sOwsJYoWmTTQyhpEhjIxhdOcF2AnggW1nMUGs0rQdITtCNoTsCN0DOwFMsO38nCACNO1GKBb3wU4AE2w7TxIESdNehGLRCHYCmEhspw+hWICdAC4S27mEUCx+BjsBTICdQOYCdgKZC9gJZC5gJ5C5gJ1A5gJ2ApkL2AlkLmAnkLmAnUDmAnYCmQvYCWQuYCeQuYCdQOYCdgKZy38AHVLCsLJuR8cAAAAASUVORK5CYII=" alt="" />

主要文件有Index.cshtml ,ErJLDController.cs ,还有数据库文件 。

1、首先在数据库中创建省级、城市的表,我的表如下:我用了一张表放下了省级、城市的数据,用level划分省份和城市,parentId表示该城市所在省份的id

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAaoAAAFYCAIAAACNty+zAAAdHklEQVR4nO2dwW7cVpaG+T5pLV2I9QrdaMCPMHJQi0HQgF6iAVkB5EeoWQTohdGKBwNhFrOYxSx6Nx0ZykZAEseO0z2bKE5sSaUSOIuqYl3ynnvrr7KLp4r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BKwVKHTlDmOqglQ5aKVDqCAB6yv8DXYWEeeynb44AAAAASUVORK5CYII=" alt="" />

 namespace Mvcproject.Controllers
{
//二级联动
public class ErJLDController : Controller
{ ZjbEntities db = new ZjbEntities();
//
// GET: /Test/ public ActionResult Index()
{
//pro_city province=new pro_city(); return View();
} public JsonResult getProvince() { List<pro_city> provinceList = (from p in db.pro_city where p.level == 1 select p).ToList(); JsonResult Jprovince = new JsonResult();
Jprovince.Data = provinceList;
Jprovince.JsonRequestBehavior = JsonRequestBehavior.AllowGet;
return Jprovince; } public JsonResult getCity(string pName)
{ //string pid = (from p in db.pro_city where p.areaValue == pName select p.id).ToString();
//int id = int.Parse(pid);
int id = int.Parse(pName); List<pro_city> cityList = (from p in db.pro_city where p.parentId == id select p).ToList(); JsonResult Jcity = new JsonResult();
Jcity.Data = cityList;
Jcity.JsonRequestBehavior = JsonRequestBehavior.AllowGet;
return Jcity; } }
}

ErJLDController.cs

 <body>
<div>
<select id="provinceId" >
<option> 请选择省份</option>
</select>
<select id="cityId">
<option>请选择市区</option>
</select>
</div> <script type="text/javascript"> //用json从数据库里取一级列表的参数
$(function () { $.getJSON("ErJLD/getProvince/", function (obj) {
$.each(obj, function (i, p) {
$("#provinceId").append("<option value='"+p.id+"'>" + p.areaValue + "</option>");
}); $("#provinceId").change(function () {
//用attr()方法获取当前选择的option的value值(即p.id ,数据库里的id值,
//虽然在TestController中的getCity方法中传入的是string类型的形参,但是后来需要变换成int类型, 所以value值应该为数字)
var pName = $("#provinceId").attr("value");
$.getJSON("ErJLD/getCity?pName=" + pName, getcity);
});
});
}); function getcity(obj) {
$("#cityId").empty();
$.each(obj, function (m, v) {
$("#cityId").append("<option >" + v.areaValue + "</option>");
}); }; </script>
</body>

Index.cshtml

04-14 22:25