zoukankan      html  css  js  c++  java
  • MVC4中control的增删改查

     public class TestController : Controller
        {
            private LeaveEntities db = new LeaveEntities();
    
            //
            // GET: /Test/
    
            public ActionResult Index()
            {
                return View(db.termtimes.ToList());
            }
    
            //
            // GET: /Test/Details/5
    
            public ActionResult Details(int id = 0)
            {
                termtime termtime = db.termtimes.Find(id);
                if (termtime == null)
                {
                    return HttpNotFound();
                }
                return View(termtime);
            }
    
            //
            // GET: /Test/Create
    
            public ActionResult Create()
            {
                return View();
            }
    
            //
            // POST: /Test/Create
    
            [HttpPost]
            [ValidateAntiForgeryToken]
            public ActionResult Create(termtime termtime)
            {
                if (ModelState.IsValid)
                {
                    db.termtimes.Add(termtime);
                    db.SaveChanges();
                    return RedirectToAction("Index");
                }
    
                return View(termtime);
            }
    
            //
            // GET: /Test/Edit/5
    
            public ActionResult Edit(int id = 0)
            {
                termtime termtime = db.termtimes.Find(id);
                if (termtime == null)
                {
                    return HttpNotFound();
                }
                return View(termtime);
            }
    
            //
            // POST: /Test/Edit/5
    
            [HttpPost]
            [ValidateAntiForgeryToken]
            public ActionResult Edit(termtime termtime)
            {
                if (ModelState.IsValid)
                {
                    db.Entry(termtime).State = EntityState.Modified;
                    db.SaveChanges();
                    return RedirectToAction("Index");
                }
                return View(termtime);
            }
    
            //
            // GET: /Test/Delete/5
    
            public ActionResult Delete(int id = 0)
            {
                termtime termtime = db.termtimes.Find(id);
                if (termtime == null)
                {
                    return HttpNotFound();
                }
                return View(termtime);
            }
    
            //
            // POST: /Test/Delete/5
    
            [HttpPost, ActionName("Delete")]
            [ValidateAntiForgeryToken]
            public ActionResult DeleteConfirmed(int id)
            {
                termtime termtime = db.termtimes.Find(id);
                db.termtimes.Remove(termtime);
                db.SaveChanges();
                return RedirectToAction("Index");
            }
    
            protected override void Dispose(bool disposing)
            {
                db.Dispose();
                base.Dispose(disposing);
            }
        }
  • 相关阅读:
    vue分页效果
    百度联想
    【java基础之jdk源码】集合类
    【java基础之jdk源码】Object
    深入理解abstract class和interface
    mysql索引类型 normal, unique, full text
    JSP中两种include的区别
    详解mysql int类型的长度值问题
    《Think in JAVA》之每日一读(initianlize)——2013/11/12、13
    探索ORM ————iBati(一)
  • 原文地址:https://www.cnblogs.com/lunawzh/p/6524723.html
Copyright © 2011-2022 走看看