1.添加引用 using System.Web.Services; 2.添加方法 [WebMethod] public static string getFoodClasses(int parentID) { onnEntities onndb = new onnEntities(); //定義數據 ...
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;
}