基本信息
源码名称:基于ASP.net的前端batatables增删查改例子
源码大小:21.44M
文件格式:.rar
开发语言:ASP
更新时间:2015-11-29
友情提示:(无需注册或充值,赞助后即可获取资源下载链接)
嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300
本次赞助数额为: 5 元×
微信扫码支付:5 元
×
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
源码介绍
环境:VS2013 SQL2008
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Net;
using System.Web;
using System.Web.Mvc;
using WebApplication3;
namespace WebApplication3.Controllers
{
public class DtController : Controller
{
private datatableEntities db = new datatableEntities();
// GET: /Dt/
public ActionResult Index()
{
return View();
}
public ActionResult GetMessage() {
var Model = db.student.ToList();
var json = new
{
data = (
from r in Model
select new
{
Id = r.Id,
Name = r.Name,
Sex = r.Sex,
Age = r.Age,
Political = r.Political,
Origin = r.Origin,
Dept = r.Dept,
}
).ToArray()
};
return Json(json, JsonRequestBehavior.AllowGet);
}
// GET: /Dt/Details/5
public ActionResult Details(int? id)
{
if (id == null)
{
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
}
student student = db.student.Find(id);
if (student == null)
{
return HttpNotFound();
}
return View(student);
}
public ActionResult Create(student st)
{
if (CreateAdd(st))
{
return Json(st, JsonRequestBehavior.AllowGet);
}
else
{
return Content("添加失败!!");
}
}
public bool CreateAdd(student st)
{
db.student.Add(st);
db.Configuration.ValidateOnSaveEnabled = false;
return db.SaveChanges() > 0;
}
public ActionResult Update(student st)
{
if (UpdateAdd(st))
{
return Content("OK");
}
else
{
return Content("NO");
}
}
public bool UpdateAdd(student st)
{
var model = db.student.Where(a => a.Id == st.Id).FirstOrDefault();
model.Name = st.Name;
model.Sex = st.Sex;
model.Age = st.Age;
model.Political = st.Political;
model.Origin = st.Origin;
model.Dept = st.Dept;
db.Set<student>().Attach(model);
db.Entry<student>(model).State = EntityState.Modified;
return db.SaveChanges()>0;
}
public ActionResult Del(int id)
{
if (Delete(id))
{
return Content("OK");
}
else
{
return Content("NO");
}
}
public bool Delete(int id)
{
var s = db.student.Where(p => p.Id == id).First();
db.student.Attach(s);
db.Entry(s).State = EntityState.Deleted;
return db.SaveChanges()>0;
}
protected override void Dispose(bool disposing)
{
if (disposing)
{
db.Dispose();
}
base.Dispose(disposing);
}
}
}
环境:VS2013 SQL2008
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Net;
using System.Web;
using System.Web.Mvc;
using WebApplication3;
namespace WebApplication3.Controllers
{
public class DtController : Controller
{
private datatableEntities db = new datatableEntities();
// GET: /Dt/
public ActionResult Index()
{
return View();
}
public ActionResult GetMessage() {
var Model = db.student.ToList();
var json = new
{
data = (
from r in Model
select new
{
Id = r.Id,
Name = r.Name,
Sex = r.Sex,
Age = r.Age,
Political = r.Political,
Origin = r.Origin,
Dept = r.Dept,
}
).ToArray()
};
return Json(json, JsonRequestBehavior.AllowGet);
}
// GET: /Dt/Details/5
public ActionResult Details(int? id)
{
if (id == null)
{
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
}
student student = db.student.Find(id);
if (student == null)
{
return HttpNotFound();
}
return View(student);
}
public ActionResult Create(student st)
{
if (CreateAdd(st))
{
return Json(st, JsonRequestBehavior.AllowGet);
}
else
{
return Content("添加失败!!");
}
}
public bool CreateAdd(student st)
{
db.student.Add(st);
db.Configuration.ValidateOnSaveEnabled = false;
return db.SaveChanges() > 0;
}
public ActionResult Update(student st)
{
if (UpdateAdd(st))
{
return Content("OK");
}
else
{
return Content("NO");
}
}
public bool UpdateAdd(student st)
{
var model = db.student.Where(a => a.Id == st.Id).FirstOrDefault();
model.Name = st.Name;
model.Sex = st.Sex;
model.Age = st.Age;
model.Political = st.Political;
model.Origin = st.Origin;
model.Dept = st.Dept;
db.Set<student>().Attach(model);
db.Entry<student>(model).State = EntityState.Modified;
return db.SaveChanges()>0;
}
public ActionResult Del(int id)
{
if (Delete(id))
{
return Content("OK");
}
else
{
return Content("NO");
}
}
public bool Delete(int id)
{
var s = db.student.Where(p => p.Id == id).First();
db.student.Attach(s);
db.Entry(s).State = EntityState.Deleted;
return db.SaveChanges()>0;
}
protected override void Dispose(bool disposing)
{
if (disposing)
{
db.Dispose();
}
base.Dispose(disposing);
}
}
}