AJAX获取JSON WEB窗体代码
程序员文章站
2022-12-11 08:30:12
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;
}
上一篇: keepalived
下一篇: c语言实现猜数字小游戏