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);
            }
        }
  • 相关阅读:
    PAT(B) 1037 在霍格沃茨找零钱(Java)
    PAT(B) 1043 输出PATest(Java)统计
    PAT(B) 1063 计算谱半径(Java)
    绘制虚线
    contentMode
    数字签名是什么
    动态设置 button的 name 的话 闪动的问题 解决
    setValuesForKeysWithDictionary 的用法
    获得 当前时间
    iOS 键盘类型
  • 原文地址:https://www.cnblogs.com/lunawzh/p/6524723.html
Copyright © 2011-2022 走看看