我的MVC.NET

using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Net;
using System.Web;
using System.Web.Mvc;
using myMVC.Models;

namespace myMVC.Controllers
{
    public class HomeController : Controller
    {
        private Entities db = new Entities();

        // GET: /Home/
        public ActionResult Index()
        {
            return View(db.myBlogSet.ToList());
        }

        // GET: /Home/Details/5
        public ActionResult Details(int? id)
        {
            if (id == null)
            {
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }
            myBlogSet myblogset = db.myBlogSet.Find(id);
            if (myblogset == null)
            {
                return HttpNotFound();
            }
            return View(myblogset);
        }

        // GET: /Home/Create
        public ActionResult Create()
        {
            return View();
        }

        // POST: /Home/Create
        // 为了防止“过多发布”攻击,请启用要绑定到的特定属性,有关 
        // 详细信息,请参阅 http://go.microsoft.com/fwlink/?LinkId=317598
        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult Create([Bind(Include="Id,myblogs")] myBlogSet myblogset)
        {
            if (ModelState.IsValid)
            {
                db.myBlogSet.Add(myblogset);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            return View(myblogset);
        }

        // GET: /Home/Edit/5
        public ActionResult Edit(int? id)
        {
            if (id == null)
            {
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }
            myBlogSet myblogset = db.myBlogSet.Find(id);
            if (myblogset == null)
            {
                return HttpNotFound();
            }
            return View(myblogset);
        }

        // POST: /Home/Edit/5
        // 为了防止“过多发布”攻击,请启用要绑定到的特定属性,有关 
        // 详细信息,请参阅 http://go.microsoft.com/fwlink/?LinkId=317598
        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult Edit([Bind(Include="Id,myblogs")] myBlogSet myblogset)
        {
            if (ModelState.IsValid)
            {
                db.Entry(myblogset).State = EntityState.Modified;
                db.SaveChanges();
                return RedirectToAction("Index");
            }
            return View(myblogset);
        }

        // GET: /Home/Delete/5
        public ActionResult Delete(int? id)
        {
            if (id == null)
            {
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }
            myBlogSet myblogset = db.myBlogSet.Find(id);
            if (myblogset == null)
            {
                return HttpNotFound();
            }
            return View(myblogset);
        }

        // POST: /Home/Delete/5
        [HttpPost, ActionName("Delete")]
        [ValidateAntiForgeryToken]
        public ActionResult DeleteConfirmed(int id)
        {
            myBlogSet myblogset = db.myBlogSet.Find(id);
            db.myBlogSet.Remove(myblogset);
            db.SaveChanges();
            return RedirectToAction("Index");
        }

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

 

posted @ 2013-11-08 17:28  王道-旭忠著  阅读(262)  评论(0编辑  收藏  举报