标签:out list() eric odi upd public date desc add
using Modelsop; using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using Newtonsoft.Json; using System.Data.Entity.Infrastructure; using System.Data.Entity; namespace WebApplication1.Controllers { public class HomeController : Controller { SuperCodeEntities context = new SuperCodeEntities(); public ActionResult Index() { return View(); } public ActionResult About() { ViewBag.Message = "Your application description page."; return View(); } public ActionResult Contact() { ViewBag.Message = "Your contact page."; return View(); } public ActionResult Add(Test user) { string reslt = null; int reslut = 0; try { context.Test.Add(user); reslut= context.SaveChanges(); if (reslut > 0) { reslt = "添加成功!"; } else { reslt = "添加失败!"; } } catch (Exception) { throw; } return Content(JsonConvert.SerializeObject(reslt)); } public ActionResult TestList() { List<Test> tt = context.Set<Test>().ToList(); return Content(JsonConvert.SerializeObject(tt)); } public ActionResult Del(int Id) { string reslt = null; int reslut = 0; Test tt = context.Test.Where(m => m.ID == Id).FirstOrDefault(); context.Test.Attach(tt); context.Test.Remove(tt); reslut = context.SaveChanges(); if (reslut > 0) { reslt = "添加成功!"; } else { reslt = "添加失败!"; } return Content(JsonConvert.SerializeObject(reslt)); } public ActionResult Update(Test tt) { string reslt = null; int reslut = 0; var ts = context.Test.Find(tt.ID); ts.Name = tt.Name; ts.Msisdn = tt.Msisdn; context.Entry<Test>(ts).State = EntityState.Modified; reslut = context.SaveChanges(); if (reslut > 0) { reslt = "添加成功!"; } else { reslt = "添加失败!"; } return Content(JsonConvert.SerializeObject(reslt)); } public ActionResult eidt(int id) { Test tt = context.Test.Where(m => m.ID == id).FirstOrDefault(); return View(tt); } } }
标签:out list() eric odi upd public date desc add
原文地址:https://www.cnblogs.com/youmingkuang/p/9557550.html