使用 AJAX 对全国地名进行选取
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<%@ WebHandler Language="C#" Class="ccc" %>using System;using System.Web;using System.Linq; //**********using System.Collections.Generic; //********** 三个引入的命名空间using System.Text; //**********public class ccc : IHttpHandler{ public void ProcessRequest(HttpContext context) { StringBuilder str = new StringBuilder(); str.Append("["); // 字符串拼接 string s = context.Request["areacode"]; using (DataClassesDataContext con = new DataClassesDataContext()) { Listclist = new List (); clist = con.ChinaStates.Where(r => r.ParentAreaCode ==s).ToList(); int count = 0; foreach (ChinaStates c in clist) { if (count > 0) { str.Append(","); } str.Append("{\"code\":\""+c.AreaCode +"\",\"name\":\""+c.AreaName+"\"}"); count++; //将查询结果拼接成 json 对象!!!!!!! } } str.Append("]"); context.Response.Write(str); context.Response.End(); } public bool IsReusable { get { return false; } }}