zoukankan      html  css  js  c++  java
  • MVC系列博客之排球计分(六)Controller的实现(二)

    上一篇博客没有完整的展现controller的代码,现在展示一下

    HomeController

    CoachController代码如下

     public class CoachController : Controller
        {
            private gDBContext db = new gDBContext();

            //
         

            public ActionResult Index()
            {
                return View(db.Students.ToList());
            }

            //
          

            public ActionResult Details(int id = 0)
            {
                Score score = db.Students.Find(id);
                if (score == null)
                {
                    return HttpNotFound();
                }
                return View(score);
            }

            //
          

            public ActionResult Create()
            {
                return View();
            }

            //
          

            [HttpPost]
            public ActionResult Create(Score Score)
            {
                if (ModelState.IsValid)
                {
                    db.Students.Add(Score);
                    db.SaveChanges();
                    return RedirectToAction("Index");
                }

                return View(Score);
            }

     
           
            public ActionResult Edit(int id = 0)
            {
                Score score = db.Students.Find(id);
                if (score == null)
                {
                    return HttpNotFound();
                }
                return View(score);
            }



            [HttpPost]
            public ActionResult Edit(Score score)
            {
                if (ModelState.IsValid)
                {
                    db.Entry(score).State = EntityState.Modified;
                    db.SaveChanges();
                    return RedirectToAction("Index");
                }
                return View(score);
            }

            //


            public ActionResult Delete(int id = 0)
            {
                Score score = db.Students.Find(id);
                if (score == null)
                {
                    return HttpNotFound();
                }
                return View(score);
            }

            //
           

            [HttpPost, ActionName("Delete")]
            public ActionResult DeleteConfirmed(int id)
            {
                Score gzscore = db.Students.Find(id);
                db.Students.Remove(score);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            protected override void Dispose(bool disposing)
            {
                db.Dispose();
                base.Dispose(disposing);
            }
        }

    至此,controller已全部完成。

  • 相关阅读:
    bootstrap多选框
    window.open()总结
    sql游标及模仿游标操作
    表变量及临时表数据批量插入和更新 写法
    表变量类型的创建及使用
    事物及exec
    [NOI2017]蚯蚓排队
    [NOI2017]游戏
    [NOI2017]蔬菜
    luogu P4194 矩阵
  • 原文地址:https://www.cnblogs.com/shiyufan/p/7073652.html
Copyright © 2011-2022 走看看