欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

AJAX获取JSON WEB窗体代码

程序员文章站 2022-06-02 22:14:22
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;
}