在服务器端数据库新建一个表ad
在DataInfo.edxm模型中点击从数据库更新模型,发布。
就新建了一个实体ad
然后新建cs文件
1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Web; 5 using System.Web.Mvc; 6 using Newtonsoft.Json; 7 using Newtonsoft.Json.Linq; 8 9 namespace WebJSON.Controllers 10 { 11 public class AdShowController:Controller 12 { 13 DataInfo storedb = new DataInfo(); 14 public JArray Index(int adid) 15 { 16 IEnumerable<ad> ad; 17 ad = storedb.ad.Where(u => u.adid == adid); 18 string adjson = JsonConvert.SerializeObject(ad); 19 JArray adJArray = JArray.Parse(adjson); 20 21 return adJArray; 22 23 } 24 } 25 }