• 我的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);
            }
        }
    }
  • 相关阅读:
    事件委托应用:在父控件中创建子控件,并接收值
    填充树节点
    JAVA Eclipse如何安装Swing
    JAVA Eclipse开发Android如何设置滚动条最大值最小值
    JAVA Eclipse开发Android如何让屏幕保持为竖直或水平状态
    JAVA Eclipse开发Android如何让超出界面的部分自动显示滚动条
    JAVA Eclipse开发Android程序如何自定义图标
    JAVA Eclipse开发Android程序会经常闪退是怎么回事
    JAVA Eclipse的Android文件结构是怎么样的
    JAVA Eclipse的Android的进程和生命周期是什么
  • 原文地址:https://www.cnblogs.com/makewong/p/3414715.html
Copyright © 2020-2023  润新知