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);
            }
        }
  • 相关阅读:
    alpine python3中使用mysql报错ModuleNotFoundError: No module named 'MySQLdb'
    Galera集群部署
    Kibana did not load properly.Check the server output for more information。
    zabbix-server迁移
    traefik使用etcd存储配置
    Rancher2.4搭建单机版rabbitmq
    ngx_http_upstream_module模块说明
    【说明】
    运维日常集合(个人向 坚持更新)
    Linux监控-历史细项数据回溯
  • 原文地址:https://www.cnblogs.com/lunawzh/p/6524723.html
Copyright © 2011-2022 走看看