![]() |
#2
wangnannan2015-08-07 08:58
单击生成之后,生成的代码大概是这样:
只有本站会员才能查看附件,请 登录 ![]() using System; using System.Collections.Generic; using System.Data; using System.Data.Entity; using System.Linq; using using System.Web; using System.Web.Mvc; using MvcBlog.Models; namespace MvcBlog.Controllers { public class HomeController : Controller { private BlogEntities db = new BlogEntities(); // GET: Home public ActionResult Index() { return View(db.Blogs.ToList()); } // GET: Home/Details/5 public ActionResult Details(int? id) { if (id == null) { return new HttpStatusCodeResult(HttpStatusCode.BadRequest); } Blog blog = db.Blogs.Find(id); if (blog == null) { return HttpNotFound(); } return View(blog); } // GET: Home/Create public ActionResult Create() { return View(); } // POST: Home/Create // 为了防止“过多发布”攻击,请启用要绑定到的特定属性,有关 // 详细信息,请参阅 http://go.。 [HttpPost] [ValidateAntiForgeryToken] public ActionResult Create([Bind(Include = "BlogId,Title,CreateDate")] Blog blog) { if (ModelState.IsValid) { db.Blogs.Add(blog); db.SaveChanges(); return RedirectToAction("Index"); } return View(blog); } // GET: Home/Edit/5 public ActionResult Edit(int? id) { if (id == null) { return new HttpStatusCodeResult(HttpStatusCode.BadRequest); } Blog blog = db.Blogs.Find(id); if (blog == null) { return HttpNotFound(); } return View(blog); } // POST: Home/Edit/5 // 为了防止“过多发布”攻击,请启用要绑定到的特定属性,有关 // 详细信息,请参阅 http://go.。 [HttpPost] [ValidateAntiForgeryToken] public ActionResult Edit([Bind(Include = "BlogId,Title,CreateDate")] Blog blog) { if (ModelState.IsValid) { db.Entry(blog).State = EntityState.Modified; db.SaveChanges(); return RedirectToAction("Index"); } return View(blog); } // GET: Home/Delete/5 public ActionResult Delete(int? id) { if (id == null) { return new HttpStatusCodeResult(HttpStatusCode.BadRequest); } Blog blog = db.Blogs.Find(id); if (blog == null) { return HttpNotFound(); } return View(blog); } // POST: Home/Delete/5 [HttpPost, ActionName("Delete")] [ValidateAntiForgeryToken] public ActionResult DeleteConfirmed(int id) { Blog blog = db.Blogs.Find(id); db.Blogs.Remove(blog); db.SaveChanges(); return RedirectToAction("Index"); } protected override void Dispose(bool disposing) { if (disposing) { db.Dispose(); } base.Dispose(disposing); } } } |
只有本站会员才能查看附件,请 登录
添加HomeController
只有本站会员才能查看附件,请 登录