暑假對排球計分規則的更新
阿新 • • 發佈:2017-09-12
技術分享 red contex 規則 ont for turn pre toa
需求:
作為觀眾,我想知道比賽進行時的隊伍比分和比賽結束時的隊伍輸贏
運行圖:
代碼如下:
查看比賽隊伍
1 public class UpdateController : Controller 2 { 3 private 排球計分規則Context db = new 排球計分規則Context(); 4 5 // 6 // GET: /Update/ 7 8 public ActionResult Index() 9 { 10 returnView(db.Updates.ToList()); 11 } 12 13 // 14 // GET: /Update/Details/5 15 16 public ActionResult Details(int id = 0) 17 { 18 Update update = db.Updates.Find(id); 19 if (update == null) 20 { 21 return HttpNotFound();22 } 23 return View(update); 24 } 25 26 // 27 // GET: /Update/Create 28 29 public ActionResult Create() 30 { 31 return View(); 32 } 33 34 // 35 // POST: /Update/Create 36 37 [HttpPost]38 public ActionResult Create(Update update) 39 { 40 if (ModelState.IsValid) 41 { 42 db.Updates.Add(update); 43 db.SaveChanges(); 44 return RedirectToAction("Index"); 45 } 46 47 return View(update); 48 } 49 50 // 51 // GET: /Update/Edit/5 52 53 public ActionResult Edit(int id = 0) 54 { 55 Update update = db.Updates.Find(id); 56 if (update == null) 57 { 58 return HttpNotFound(); 59 } 60 return View(update); 61 } 62 63 // 64 // POST: /Update/Edit/5 65 66 [HttpPost] 67 public ActionResult Edit(Update update) 68 { 69 if (ModelState.IsValid) 70 { 71 db.Entry(update).State = EntityState.Modified; 72 db.SaveChanges(); 73 return RedirectToAction("Index"); 74 } 75 return View(update); 76 } 77 78 // 79 // GET: /Update/Delete/5 80 81 public ActionResult Delete(int id = 0) 82 { 83 Update update = db.Updates.Find(id); 84 if (update == null) 85 { 86 return HttpNotFound(); 87 } 88 return View(update); 89 } 90 91 // 92 // POST: /Update/Delete/5 93 94 [HttpPost, ActionName("Delete")] 95 public ActionResult DeleteConfirmed(int id) 96 { 97 Update update = db.Updates.Find(id); 98 db.Updates.Remove(update); 99 db.SaveChanges(); 100 return RedirectToAction("Index"); 101 } 102 103 protected override void Dispose(bool disposing) 104 { 105 db.Dispose(); 106 base.Dispose(disposing); 107 } 108 } 109 }
比賽隊伍比分視圖:
1 @model IEnumerable<排球計分規則.Models.Update> 2 3 @{ 4 ViewBag.Title = "Index"; 5 } 6 7 <h2>Index</h2> 8 9 <p> 10 @Html.ActionLink("Create New", "Create") 11 </p> 12 <table> 13 <tr> 14 <th> 15 @Html.DisplayNameFor(model => model.DName) 16 </th> 17 <th> 18 @Html.DisplayNameFor(model => model.integral) 19 </th> 20 <th></th> 21 </tr> 22 23 @foreach (var item in Model) { 24 <tr> 25 <td> 26 @Html.DisplayFor(modelItem => item.DName) 27 </td> 28 <td> 29 @Html.DisplayFor(modelItem => item.integral) 30 </td> 31 <td> 32 @Html.ActionLink("Edit", "Edit", new { id=item.PId }) | 33 @Html.ActionLink("Details", "Details", new { id=item.PId }) | 34 @Html.ActionLink("Delete", "Delete", new { id=item.PId }) 35 </td> 36 </tr> 37 } 38 39 </table>
暑假對排球計分規則的更新