JQuery Ajax implements a drop-down box with no refreshing, jqueryajax
HTML code:
@ {Layout = null ;}@ using DAL; @ 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 code:
Using System; using System. collections. generic; using System. data; using System. linq; using System. text; using System. web. mvc; using DAL; namespace Controllers. backstage {// <summary> /// Administrative region /// </summary> public class AreaController: AdminBaseController {# region constructor and variable private SQLiteHelper. SQLiteHelper sqliteHelper; private AreaDal areaDal; public AreaController () {sqliteHelper = new SQLiteHelper. SQLiteHelper (); areaDal = new AreaDal () ;}# endregion # region administrative division and business district cascade selection page public ActionResult AreaSelect () {return PartialView ();} # endregion # region get all provinces public ActionResult GetProvinces () {DataTable dt = areaDal. getProvincesAll (); StringBuilder sbHtml = new StringBuilder (); sbHtml. append ("<option value = '-1' >== select ==</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 obtain the city public ActionResult GetCities (string provinceId) {DataTable dt = areaDal. getCities (provinceId); StringBuilder sbHtml = new StringBuilder (); sbHtml. append ("<option value = '-1' >== select ==</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 obtains the public ActionResult GetCounties (string cityId) {DataTable dt = areaDal. getCounties (cityId); StringBuilder sbHtml = new StringBuilder (); sbHtml. append ("<option value = '-1' >== select ==</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 obtains the public ActionResult GetAreas (string countyId) {DataTable dt = areaDal according to the region and county. getAreas (countyId); StringBuilder sbHtml = new StringBuilder (); sbHtml. append ("<option value = '-1' >== select ==</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 }}View Code