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();
            }
        }
    }
}

视图页面(增删改查。。前台)

效果图:

时间: 2024-08-26 08:06:45

MVC自动生成增删改查的相关文章

微软Connect教程系列--自动生成增删改查页面工具介绍(二)

本章课程描述了vs2015的三个特点,其中主要将描述在vs2015下面,使用命令自动生成增删改查界面,具体如下: 1.web.config文件不在存在,用config.json替代,以适应支撑vs的插件化. 即config.json可以在项目中不存在,你可以用xml文件或其他方式创建数据库连接. 2.获取nuget包更便捷 打开project.json,在dependencies节点输入“Newtonsoft.json”,并选择好相应版本,保存后,vs的引用就会自动从nuget上下载newton

NetCore2.0 RozarPage自动生成增删改查

原文链接:https://docs.microsoft.com/zh-cn/aspnet/core/tutorials/web-api-help-pages-using-swagger 上面的只是原文的上面的链接,右边的 没有链接,不能点击,不知道为什么.不过大家可以点击下面的下载PDF,下载后打开看就可以了 准备工作 VS2017需要15.3以后的版本,且安装完NetCore2.0 SDK Net Core 2.0 SDK下载链接:https://www.microsoft.com/net/c

MyBatis Generator作为maven插件自动生成增删改查代码及配置文件例子

什么是MyBatis Generator MyBatis Generator (MBG) 是一个Mybatis的代码生成器,可以自动生成一些简单的CRUD(插入,查询,更新,删除)操作代码,model代码,及mapper配置文件: 如何配置MyBatis Generator 代码生成器(MBG)是由一个XML配置文件驱动,主要告诉MBG以下三件事 如何连接到数据库 生成什么对象,以及如何生成它们 那些表生成对象 具体如何配置,可以参考如下链接,已经有很详细的说明了: http://generat

BootstrapTable+KnockoutJS自定义T4模板快速生成增删改查页面

前言:上篇介绍了下ko增删改查的封装,确实节省了大量的js代码.博主是一个喜欢偷懒的人,总觉得这些基础的增删改查效果能不能通过一个什么工具直接生成页面效果,啥代码都不用写了,那该多爽.于是研究了下T4的语法,虽然没有完全掌握,但是算是有了一个大致的了解.于是乎有了今天的这篇文章:通过T4模板快速生成页面. KnockoutJS系列文章: JS组件系列——BootstrapTable+KnockoutJS实现增删改查解决方案(一) JS组件系列——BootstrapTable+KnockoutJS

MR_L先生 3_05_02_MSSQL课程_Ado.Net_SQLDataAdapter和SqlCommandBuilder实现自动的增删改查映射到数据库操作

using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Data.SqlClient; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespa

MVC+EF 的增删改查操作

1. //创建EF映射对象数据集 static Models.db_JiaoYouEntities DbDeleteData = new Models.db_JiaoYouEntities(); 2. #region 得到数据集合+Query() /// <summary> /// 得到数据集合 /// </summary> /// <returns></returns> public List<Models.tb_Msg> Query() {

EasyUI + Spring MVC + hibernate实现增删改查导入导出

(这是一个故事……) 前言 作为一个JAVA开发工程师,我觉得最基本是需要懂前端.后台以及数据库. 练习的内容很基础,包括:基本增删改查.模糊查询.分页查询.树菜单.上传下载.tab页 主管发我一个已经搭建好的框架平台,在平台上进行编码,不限制技术. 虽然说不限制技术,但还是得根据已经搭建的框架平台进行编码. 所以首先第一步,分析框架平台结构组成. 入手:看目录.看配置.看jar包.看js库.看数据库... 不难发现项目是基于:Spring + Hibernate + Spring MVC +

使用jdbc实现简单的mvc模式的增删改查

Mvc模式设计: 视图:添加界面(addUser.jsp),修改界面(updateUser.jsp),显示页面(allUser.jsp) 控制器:添加信息控制器(AddUserServlet),修改信息控制器(UpdateUserServlet),删除信息控制器(DeleteUserServlet),显示信息控制器(FindAllUserServlet) 模型:userbean 数据库层:DBBean 总体设计: 添加信息模块:用户通过添加信息界面(addUser.jsp)提交表单,提交的信息有

Asp.Net MVC EF-DbFirst之增删改查

控制器及动作方法: using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using Mvc5Test.Models; using System.Data.Entity.Infrastructure; namespace Mvc5Test.Controllers { //用户的请求总是先发到控制器的某个Action方法,再由Action方