zoukankan      html  css  js  c++  java
  • 控制器的设计与实现(五)

     创建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添加视图以便于了解详细得分

  • 相关阅读:
    asp.net发布网站的时候三个选项
    Web Service 异常处理
    Asp.net 缓存技术总结
    自定义控件:广告内容后期加载。以及NamingContainer层次的应用
    图片显示时加水印(不改变原图片)
    .NET 2.0中的企业库异常处理块简述
    .NET反射、委托技术与设计模式
    三角函数Table.AddColumn(Power Query 之 M 语言)
    统计信息Table.AddColumn(Power Query 之 M 语言)
    提取Table.AddColumn(Power Query 之 M 语言)
  • 原文地址:https://www.cnblogs.com/chen-bo/p/7065824.html
Copyright © 2011-2022 走看看