控制器的设计与实现

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了控制器的设计与实现相关的知识,希望对你有一定的参考价值。

 

 创建army实体模型类的控制器armyController

 技术分享

添加了队伍模型的添加,编辑,详情,删除几种方法

 相关代码如下

 

  1 using System;
  2 using System.Collections.Generic;
  3 using System.Data;
  4 using System.Linq;
  5 using System.Web;
  6 using System.Web.Mvc;
  7 using 排球计分规则.Models;
  8 
  9 namespace 排球计分规则.Controllers
 10 {
 11     public class armyController : Controller
 12     {
 13         private armyDBContext db = new armyDBContext();
 14 
 15         //
 16         // GET: /Team/
 17 
 18         public ActionResult Index()
 19         {
 20             return View(db.army.ToList());
 21         }
 22 
 23         //private ActionResult View(List<Models.army> list)
 24         //{
 25         //    throw new NotImplementedException();
 26         //}
 27 
 28         //
 29         // GET: /Team/Details/5
 30 
 31         public ActionResult Details(int id = 0)
 32         {
 33             army team = db.army.Find(id);
 34             if (team == null)
 35             {
 36                 return HttpNotFound();
 37             }
 38             return View(team);
 39         }
 40 
 41         //private ActionResult HttpNotFound()
 42         //{
 43         //    throw new NotImplementedException();
 44         //}
 45 
 46         //
 47         // GET: /Team/Create
 48 
 49         public ActionResult Create()
 50         {
 51             return View();
 52         }
 53 
 54         //
 55         // POST: /Team/Create
 56 
 57         [HttpPost]
 58         public ActionResult Create(army team)
 59         {
 60             if (ModelState.IsValid)
 61             {
 62                 db.army.Add(team);
 63                 db.SaveChanges();
 64                 return RedirectToAction("Index");
 65             }
 66 
 67             return View(team);
 68         }
 69 
 70         //
 71         // GET: /Team/Edit/5
 72 
 73         public ActionResult Edit(int id = 0)
 74         {
 75             army team = db.army.Find(id);
 76             if (team == null)
 77             {
 78                 return HttpNotFound();
 79             }
 80             return View(team);
 81         }
 82 
 83         //
 84         // POST: /Team/Edit/5
 85 
 86         [HttpPost]
 87         public ActionResult Edit(army team)
 88         {
 89             if (ModelState.IsValid)
 90             {
 91                 db.Entry(team).State = EntityState.Modified;
 92                 db.SaveChanges();
 93                 return RedirectToAction("Index");
 94             }
 95             return View(team);
 96         }
 97 
 98         //
 99         // GET: /Team/Delete/5
100 
101         public ActionResult Delete(int id = 0)
102         {
103             army team = db.army.Find(id);
104             if (team == null)
105             {
106                 return HttpNotFound();
107             }
108             return View(team);
109         }
110 
111         //
112         // POST: /Team/Delete/5
113 
114         [HttpPost, ActionName("Delete")]
115         public ActionResult DeleteConfirmed(int id)
116         {
117             army team = db.army.Find(id);
118             db.army.Remove(team);
119             db.SaveChanges();
120             return RedirectToAction("Index");
121         }
122 
123         protected override void Dispose(bool disposing)
124         {
125             db.Dispose();
126             base.Dispose(disposing);
127         }
128     }
129 }

 接下来在Armys添加视图以便于了解详细得分

以上是关于控制器的设计与实现的主要内容,如果未能解决你的问题,请参考以下文章

Java 封装

Java 封装

Java 封装

Java封装

使用 BottomAppBar 材料设计组件的片段过渡

Java基础:封装