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);
            }
        }
  • 相关阅读:
    $$Ctrl+shift+M分数罗马字母小写
    设置字体大小加粗斜体下划线
    无序列表有序列表
    数学公式插入
    文本居中、代码插入、图片插入
    VM 使用问题 | 安装失败->>注册表
    VM小技巧——虚拟机解决vm窗口太小的办法
    OneNet平台实践
    linux 打包 | autoconf 使用方法
    C 总结 | 复习注意点
  • 原文地址:https://www.cnblogs.com/lunawzh/p/6524723.html
Copyright © 2011-2022 走看看