MVC系列博客之排球计分(六)Controller的实现(二)
2021-07-15 05:07
标签:hang res 博客 mvc result delete lstat ase post 上一篇博客没有完整的展现controller的代码,现在展示一下 HomeController CoachController代码如下 public class CoachController : Controller // public ActionResult Index() // public ActionResult Details(int id = 0) // public ActionResult Create() // [HttpPost] return View(Score); [HttpPost] // // [HttpPost, ActionName("Delete")] protected override void Dispose(bool disposing) 至此,controller已全部完成。 MVC系列博客之排球计分(六)Controller的实现(二) 标签:hang res 博客 mvc result delete lstat ase post 原文地址:http://www.cnblogs.com/shiyufan/p/7073652.html
{
private gDBContext db = new gDBContext();
{
return View(db.Students.ToList());
}
{
Score score = db.Students.Find(id);
if (score == null)
{
return HttpNotFound();
}
return View(score);
}
{
return View();
}
public ActionResult Create(Score Score)
{
if (ModelState.IsValid)
{
db.Students.Add(Score);
db.SaveChanges();
return RedirectToAction("Index");
}
}
public ActionResult Edit(int id = 0)
{
Score score = db.Students.Find(id);
if (score == null)
{
return HttpNotFound();
}
return View(score);
}
public ActionResult Edit(Score score)
{
if (ModelState.IsValid)
{
db.Entry(score).State = EntityState.Modified;
db.SaveChanges();
return RedirectToAction("Index");
}
return View(score);
}
public ActionResult Delete(int id = 0)
{
Score score = db.Students.Find(id);
if (score == null)
{
return HttpNotFound();
}
return View(score);
}
public ActionResult DeleteConfirmed(int id)
{
Score gzscore = db.Students.Find(id);
db.Students.Remove(score);
db.SaveChanges();
return RedirectToAction("Index");
}
{
db.Dispose();
base.Dispose(disposing);
}
}
上一篇:常用且难记的一些css
文章标题:MVC系列博客之排球计分(六)Controller的实现(二)
文章链接:http://soscw.com/index.php/essay/105434.html