AJAX获取JSON WEB窗体代码

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;
}

posted @ 2018-09-16 23:33  Gurder  阅读(407)  评论(1编辑  收藏  举报