AJAX獲取JSON WEB窗體程式碼
阿新 • • 發佈:2018-12-10
1.新增引用 using System.Web.Services;
2.新增方法
[WebMethod] public static string getFoodClasses(int parentID) { onnEntities onndb = new onnEntities(); //定義資料連線物件 string strJson = "{\"classlist\":["; IQueryable<food_class> fcList = onndb.food_class.Where(s => s.class_ParentClassID == parentID); foreach (food_class i in fcList) { strJson += "{\"id\": " + i.class_ID + ",\"title\":\" " + i.class_Title + "\"},"; } strJson = strJson.Substring(0, strJson.Length - 1); strJson += "]}"; return strJson; }