本文实例为大家分享了jQuery Ajax实现下拉框无刷新联动的具体代码,供大家参考,具体内容如下
@using DAL;
@using System.Data;商圈选择
@H_301_10@
@using System.Data;
@{
AreaDal areaDal = new AreaDal();
string areaId = ViewBag.areaId;
DataRow drArea = areaDal.GetArea(areaId);
string countyId = drArea == null ? "-1" : drArea["countyId"].ToString();
DataRow drCounty = areaDal.GetCounty(countyId);
string cityId = drCounty == null ? "-1" : drCounty["cityId"].ToString();
DataRow drCity = areaDal.GetCity(cityId);
string provinceId = drCity == null ? "-1" : drCity["provinceId"].ToString();
}
<!DOCTYPE html>
Controller代码:
namespace Controllers.Backstage
{
///
/// 行政区划
///
public class AreaController : AdminBaseController
{
{
///
/// 行政区划
///
public class AreaController : AdminBaseController
{
region 构造函数及变量
private <a href="/tag/sql/" target="_blank" class="keywords">sql</a>iteHelper.<a href="/tag/sql/" target="_blank" class="keywords">sql</a>iteHelper <a href="/tag/sql/" target="_blank" class="keywords">sql</a>iteHelper;
private AreaDal areaDal;
public AreaController()
{
<a href="/tag/sql/" target="_blank" class="keywords">sql</a>iteHelper = new <a href="/tag/sql/" target="_blank" class="keywords">sql</a>iteHelper.<a href="/tag/sql/" target="_blank" class="keywords">sql</a>iteHelper();
areaDal = new AreaDal();
}
#endregion
#region 行政区划商圈级联选择<a href="/tag/yemian/" target="_blank" class="keywords">页面</a>
public ActionResult AreaSelect()
{
return PartialView();
}
#endregion
#region <a href="/tag/huoqu/" target="_blank" class="keywords">获取</a>全部省
public ActionResult GetProvinces()
{
DataTable dt = areaDal.GetProvincesAll();
StringBuilder sbHtml = new StringBuilder();
sbHtml.Append("<option value='-1'>==请选择==</option>");
foreach (DataRow dr in dt.Rows)
{
sbHtml.AppendFormat("<option value='{0}'>{1}</option>",dr["id"].ToString(),dr["name"].ToString());
}
return Content(sbHtml.ToString());
}
#endregion
#region 根据省<a href="/tag/huoqu/" target="_blank" class="keywords">获取</a>市
public ActionResult GetCities(string provinceId)
{
DataTable dt = areaDal.GetCities(provinceId);
StringBuilder sbHtml = new StringBuilder();
sbHtml.Append("<option value='-1'>==请选择==</option>");
foreach (DataRow dr in dt.Rows)
{
sbHtml.AppendFormat("<option value='{0}'>{1}</option>",dr["name"].ToString());
}
return Content(sbHtml.ToString());
}
#endregion
#region 根据市<a href="/tag/huoqu/" target="_blank" class="keywords">获取</a>区县
public ActionResult GetCounties(string cityId)
{
DataTable dt = areaDal.GetCounties(cityId);
StringBuilder sbHtml = new StringBuilder();
sbHtml.Append("<option value='-1'>==请选择==</option>");
foreach (DataRow dr in dt.Rows)
{
sbHtml.AppendFormat("<option value='{0}'>{1}</option>",dr["name"].ToString());
}
return Content(sbHtml.ToString());
}
#endregion
#region 根据区县<a href="/tag/huoqu/" target="_blank" class="keywords">获取</a>商圈
public ActionResult GetAreas(string countyId)
{
DataTable dt = areaDal.GetAreas(countyId);
StringBuilder sbHtml = new StringBuilder();
sbHtml.Append("<option value='-1'>==请选择==</option>");
foreach (DataRow dr in dt.Rows)
{
sbHtml.AppendFormat("<option value='{0}'>{1}</option>",dr["name"].ToString());
}
return Content(sbHtml.ToString());
}
#endregion
}
}