一、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")
@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)
}
@Html.ActionLink("返回首页", "Index")
@section Scripts {
@Scripts.Render("~/bundles/jqueryval")
}
3、Details.cshtml
@model MvcVolleyball.Models.Ju
@{
ViewBag.Title = "Details";
}
详细信息
@Html.ActionLink("编辑", "Edit", new { id=Model.JId }) |
@Html.ActionLink("返回首页", "Index")
4、Delete.cshtml
@model MvcVolleyball.Models.Ju
@{
ViewBag.Title = "Delete";
}
删除
确认删除?
@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)
}
@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)
}
@Html.ActionLink("返回分数首页", "Index")
@section Scripts {
@Scripts.Render("~/bundles/jqueryval")
}
2、Delete.cshtml
@model MvcVolleyball.Models.Score
@{
ViewBag.Title = "Delete";
}
删除
确认删除?
@using (Html.BeginForm()) {
@Html.AntiForgeryToken()
|
@Html.ActionLink("返回分数首页", "Index")
}
3、Details.cshtml
@model MvcVolleyball.Models.Score
@{
ViewBag.Title = "Details";
}
详细信息
@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)
}
@Html.ActionLink("返回分数首页", "Index")
@section Scripts {
@Scripts.Render("~/bundles/jqueryval")
}
5、Index.cshtml
@model IEnumerable
@{
ViewBag.Title = "Index";
}
分数首页
@Html.ActionLink("添加数据", "Create")
@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")