JQuery Ajax implements a drop-down box with no refreshing, jqueryajax

Source: Internet
Author: User

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

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.