zoukankan      html  css  js  c++  java
  • MVC自动生成增删改查

    1)创建控制器

    生成代码如下(增删改查。。。)

    using MvcApplication32.Models;
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.Mvc;
    
    namespace MvcApplication32.Controllers
    {
        public class UserController : Controller
        {
            //
            // GET: /User/
            test1Entities db = new test1Entities();
            public ActionResult Index()
            {
                ViewData.Model = db.UserInfo.AsEnumerable();
                return View();
            }
    
            //
            // GET: /User/Details/5
    
            public ActionResult Details(int id)
            {
                return View();
            }
    
            //
            // GET: /User/Create
    
            public ActionResult Create()
            {
                return View();
            }
    
            //
            // POST: /User/Create
    
            [HttpPost]
            public ActionResult Create(FormCollection collection)
            {
                try
                {
                    // TODO: Add insert logic here
    
                    return RedirectToAction("Index");
                }
                catch
                {
                    return View();
                }
            }
    
            //
            // GET: /User/Edit/5
    
            public ActionResult Edit(int id)
            {
                return View();
            }
    
            //
            // POST: /User/Edit/5
    
            [HttpPost]
            public ActionResult Edit(int id, FormCollection collection)
            {
                try
                {
                    // TODO: Add update logic here
    
                    return RedirectToAction("Index");
                }
                catch
                {
                    return View();
                }
            }
    
            //
            // GET: /User/Delete/5
    
            public ActionResult Delete(int id)
            {
                return View();
            }
    
            //
            // POST: /User/Delete/5
    
            [HttpPost]
            public ActionResult Delete(int id, FormCollection collection)
            {
                try
                {
                    // TODO: Add delete logic here
    
                    return RedirectToAction("Index");
                }
                catch
                {
                    return View();
                }
            }
        }
    }
    自动生成增删改查。。后台。

    2)添加index列表(list)视图

    using MvcApplication32.Models;
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.Mvc;
    
    namespace MvcApplication32.Controllers
    {
        public class UserController : Controller
        {
            //
            // GET: /User/
            test1Entities db = new test1Entities();
            public ActionResult Index()
            {
                ViewData.Model = db.UserInfo.AsEnumerable();
                return View();
            }
    
            //
            // GET: /User/Details/5
    
            public ActionResult Details(int id)
            {
                return View();
            }
    
            //
            // GET: /User/Create
    
            public ActionResult Create()
            {
                return View();
            }
    
            //
            // POST: /User/Create
    
            [HttpPost]
            public ActionResult Create(FormCollection collection)
            {
                try
                {
                    // TODO: Add insert logic here
    
                    return RedirectToAction("Index");
                }
                catch
                {
                    return View();
                }
            }
    
            //
            // GET: /User/Edit/5
    
            public ActionResult Edit(int id)
            {
                return View();
            }
    
            //
            // POST: /User/Edit/5
    
            [HttpPost]
            public ActionResult Edit(int id, FormCollection collection)
            {
                try
                {
                    // TODO: Add update logic here
    
                    return RedirectToAction("Index");
                }
                catch
                {
                    return View();
                }
            }
    
            //
            // GET: /User/Delete/5
    
            public ActionResult Delete(int id)
            {
                return View();
            }
    
            //
            // POST: /User/Delete/5
    
            [HttpPost]
            public ActionResult Delete(int id, FormCollection collection)
            {
                try
                {
                    // TODO: Add delete logic here
    
                    return RedirectToAction("Index");
                }
                catch
                {
                    return View();
                }
            }
        }
    }
    视图页面(增删改查。。前台)

    效果图:

    转载 请注明原文地址并标明转载:http://www.cnblogs.com/laopo 商业用途请与我联系:lcfhn168@163.com
  • 相关阅读:
    MySQL中的字符串函数
    用google map实现周边搜索功能
    用 wait-notify 写一段代码来解决生产者-消费者问题
    equals和hashcode为什么要一起重写
    Java知多少(107)几个重要的java数据库访问类和接口
    Java知多少(106)程序与数据库连接
    Java知多少(105)套接字(Socket)
    Java知多少(104)网络编程之统一资源定位符URL
    Java知多少(103)网络编程之IP地址和InetAddress类
    Java知多少(102)多媒体基础
  • 原文地址:https://www.cnblogs.com/laopo/p/4782702.html
Copyright © 2011-2022 走看看