1)创建控制器

MVC自动生成增删改查

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

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();
            }
        }
    }
}
自动生成增删改查。。后台。

相关文章:

  • 2021-10-12
  • 2021-05-30
  • 2022-12-23
  • 2021-07-08
  • 2022-01-04
  • 2021-12-31
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-10-07
  • 2023-01-11
  • 2022-02-27
  • 2022-01-14
  • 2022-12-23
  • 2021-12-09
  • 2021-05-19
相关资源
相似解决方案