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已全部完成。

  • 相关阅读:
    OOP侧边分享按钮
    表格基础操作
    行为型模式之自定义语言的实现(解释器模式)
    行为型模式之请求发送者与接收者解耦(命令模式)
    行为型模式之请求的链式处理(职责链模式)
    Http、Socket、WebSocket之间联系与区别
    日期时间工具类DateTimeUtil(基于Java8的LocalDateTime)
    结构型模式之代理模式
    Java8 函数式接口@FunctionalInterface的使用说明
    结构型模式之实现对象的复用(享元模式)
  • 原文地址:https://www.cnblogs.com/shiyufan/p/7073652.html
Copyright © 2011-2022 走看看