MVC之排球比赛计分程序 ——(八)具体代码(1)

2021-07-15 11:04

阅读:607

标签:view   bool   base   move   elf   list   modified   field   val   

一、JuController代码如下:

  public class JuController : Controller
    {
        private CountScoreDBContext db = new CountScoreDBContext();

        //
        // GET: /Ju/

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

        //
        // GET: /Ju/Details/5

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

        //
        // GET: /Ju/Create

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

        //
        // POST: /Ju/Create

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

            return View(ju);
        }

        //
        // GET: /Ju/Edit/5

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

        //
        // POST: /Ju/Edit/5

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

        //
        // GET: /Ju/Delete/5

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

        //
        // POST: /Ju/Delete/5

        [HttpPost, ActionName("Delete")]
        [ValidateAntiForgeryToken]
        public ActionResult DeleteConfirmed(int id)
        {
            Ju ju = db.Ju.Find(id);
            db.Ju.Remove(ju);
            db.SaveChanges();
            return RedirectToAction("Index");
        }

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

所对应的增删改查视图:

1、Index.cshtml

@model IEnumerable

@{
    ViewBag.Title = "Index";
}

局分首页


    @Html.ActionLink("添加局分数据", "Create")



   
       
       
      
       
   

@foreach (var item in Model) {
   


       
       
      
       
   
}


            @Html.DisplayNameFor(model => model.JUCi)
       

            @Html.DisplayNameFor(model => model.JScore)
       

            @Html.DisplayFor(modelItem => item.JUCi)
       

            @Html.DisplayFor(modelItem => item.JScore)
       

            @Html.ActionLink("编辑", "Edit", new { id=item.JId }) |
            @Html.ActionLink("详细信息", "Details", new { id=item.JId }) |
            @Html.ActionLink("删除", "Delete", new { id=item.JId })
       

  @Html.ActionLink("返回首页", "Index","Team")

2、Edit.cshtml

@model MvcVolleyball.Models.Ju

@{
    ViewBag.Title = "Edit";
}

编辑

@using (Html.BeginForm()) {
    @Html.AntiForgeryToken()
    @Html.ValidationSummary(true)

   


        Ju

        @Html.HiddenFor(model => model.JId)

       


            @Html.LabelFor(model => model.JUCi)
       

       

            @Html.EditorFor(model => model.JUCi)
            @Html.ValidationMessageFor(model => model.JUCi)
       

       


            @Html.LabelFor(model => model.JScore)
       

       

            @Html.EditorFor(model => model.JScore)
            @Html.ValidationMessageFor(model => model.JScore)
       

    
       


           
       


   

}


    @Html.ActionLink("返回首页", "Index")

@section Scripts {
    @Scripts.Render("~/bundles/jqueryval")
}

3、Details.cshtml

@model MvcVolleyball.Models.Ju

@{
    ViewBag.Title = "Details";
}

详细信息


    Ju

   


         @Html.DisplayNameFor(model => model.JUCi)
   

   

        @Html.DisplayFor(model => model.JUCi)
   

   


         @Html.DisplayNameFor(model => model.JScore)
   

   

        @Html.DisplayFor(model => model.JScore)
   

 



    @Html.ActionLink("编辑", "Edit", new { id=Model.JId }) |
    @Html.ActionLink("返回首页", "Index")

4、Delete.cshtml

@model MvcVolleyball.Models.Ju

@{
    ViewBag.Title = "Delete";
}

删除

确认删除?



    Ju

   


         @Html.DisplayNameFor(model => model.JUCi)
   

   

        @Html.DisplayFor(model => model.JUCi)
   

   


         @Html.DisplayNameFor(model => model.JScore)
   

   

        @Html.DisplayFor(model => model.JScore)
   

 


@using (Html.BeginForm()) {
    @Html.AntiForgeryToken()
   


        |
        @Html.ActionLink("返回首页", "Index")
   


}

5、Create.cshtml

@model MvcVolleyball.Models.Ju

@{
    ViewBag.Title = "Create";
}

添加数据

@using (Html.BeginForm()) {
    @Html.AntiForgeryToken()
    @Html.ValidationSummary(true)

   


        Ju

       


            @Html.LabelFor(model => model.JUCi)
       

       

            @Html.EditorFor(model => model.JUCi)
            @Html.ValidationMessageFor(model => model.JUCi)
       

       


            @Html.LabelFor(model => model.JScore)
       

       

            @Html.EditorFor(model => model.JScore)
            @Html.ValidationMessageFor(model => model.JScore)
       


       


           
       


   

}


    @Html.ActionLink("返回首页", "Index")

@section Scripts {
    @Scripts.Render("~/bundles/jqueryval")
}

二、ScoreController代码如下:

 public class ScoreController : Controller
    {
        private CountScoreDBContext db = new CountScoreDBContext();

        //
        // GET: /Score/

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

        //
        // GET: /Score/Details/5

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

        //
        // GET: /Score/Create

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

        //
        // POST: /Score/Create

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

            return View(score);
        }

        //
        // GET: /Score/Edit/5

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

        //
        // POST: /Score/Edit/5

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

        //
        // GET: /Score/Delete/5

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

        //
        // POST: /Score/Delete/5

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

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

1、Create.cshtml

@model MvcVolleyball.Models.Score

@{
    ViewBag.Title = "Create";
}

添加数据

@using (Html.BeginForm()) {
    @Html.AntiForgeryToken()
    @Html.ValidationSummary(true)

   


        Score

       


            @Html.LabelFor(model => model.AScore)
       

       

            @Html.EditorFor(model => model.AScore)
            @Html.ValidationMessageFor(model => model.AScore)
       

       


            @Html.LabelFor(model => model.BScore)
       

       

            @Html.EditorFor(model => model.BScore)
            @Html.ValidationMessageFor(model => model.BScore)
       

       


            @Html.LabelFor(model => model.Note)
       

       

            @Html.EditorFor(model => model.Note)
            @Html.ValidationMessageFor(model => model.Note)
       

    

       


           
       


   

}


    @Html.ActionLink("返回分数首页", "Index")

@section Scripts {
    @Scripts.Render("~/bundles/jqueryval")
}

2、Delete.cshtml

@model MvcVolleyball.Models.Score

@{
    ViewBag.Title = "Delete";
}

删除

确认删除?



    Score

   


         @Html.DisplayNameFor(model => model.AScore)
   

   

        @Html.DisplayFor(model => model.AScore)
   

   


         @Html.DisplayNameFor(model => model.BScore)
   

   

        @Html.DisplayFor(model => model.BScore)
   

   


         @Html.DisplayNameFor(model => model.Note)
   

   

        @Html.DisplayFor(model => model.Note)
   

 


@using (Html.BeginForm()) {
    @Html.AntiForgeryToken()
   


        |
        @Html.ActionLink("返回分数首页", "Index")
   


}

3、Details.cshtml

@model MvcVolleyball.Models.Score

@{
    ViewBag.Title = "Details";
}

详细信息


    Score

   


         @Html.DisplayNameFor(model => model.AScore)
   

   

        @Html.DisplayFor(model => model.AScore)
   

   


         @Html.DisplayNameFor(model => model.BScore)
   

   

        @Html.DisplayFor(model => model.BScore)
   

   


         @Html.DisplayNameFor(model => model.Note)
   

   

        @Html.DisplayFor(model => model.Note)
   

 



    @Html.ActionLink("编辑", "Edit", new { id=Model.SId }) |
    @Html.ActionLink("返回分数首页", "Index")

4、Edit.cshtml

@model MvcVolleyball.Models.Score

@{
    ViewBag.Title = "Edit";
}

编辑

@using (Html.BeginForm()) {
    @Html.AntiForgeryToken()
    @Html.ValidationSummary(true)

   


        Score

        @Html.HiddenFor(model => model.SId)

       


            @Html.LabelFor(model => model.AScore)
       

       

            @Html.EditorFor(model => model.AScore)
            @Html.ValidationMessageFor(model => model.AScore)
       

       


            @Html.LabelFor(model => model.BScore)
       

       

            @Html.EditorFor(model => model.BScore)
            @Html.ValidationMessageFor(model => model.BScore)
       

       


            @Html.LabelFor(model => model.Note)
       

       

            @Html.EditorFor(model => model.Note)
            @Html.ValidationMessageFor(model => model.Note)
       

      
       


           
       


   

}


    @Html.ActionLink("返回分数首页", "Index")

@section Scripts {
    @Scripts.Render("~/bundles/jqueryval")
}

5、Index.cshtml

@model IEnumerable

@{
    ViewBag.Title = "Index";
}

分数首页


    @Html.ActionLink("添加数据", "Create")



   
       
       
       
    
       
   

@foreach (var item in Model) {
   


       
       
       
      
       
   
}


            @Html.DisplayNameFor(model => model.AScore)
       

            @Html.DisplayNameFor(model => model.BScore)
       

            @Html.DisplayNameFor(model => model.Note)
       

            @Html.DisplayFor(modelItem => item.AScore)
       

            @Html.DisplayFor(modelItem => item.BScore)
       

            @Html.DisplayFor(modelItem => item.Note)
       

            @Html.ActionLink("编辑", "Edit", new { id=item.SId }) |
            @Html.ActionLink("详细信息", "Details", new { id=item.SId }) |
            @Html.ActionLink("删除", "Delete", new { id=item.SId })
       

  @Html.ActionLink("返回局首页", "Index","Ju")

 

MVC之排球比赛计分程序 ——(八)具体代码(1)

标签:view   bool   base   move   elf   list   modified   field   val   

原文地址:http://www.cnblogs.com/150902yt/p/7073033.html


评论


亲,登录后才可以留言!