MVC automatically generates additions and deletions and changes

Source: Internet
Author: User

1) Create a controller

Generate the code as follows (add and revise ...) )

usingMvcapplication32.models;usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingsystem.web;usingSYSTEM.WEB.MVC;namespacemvcapplication32.controllers{ Public classUsercontroller:controller {//        //GET:/user/Test1entities db =Newtest1entities ();  PublicActionResult Index () {Viewdata.model=db.            Userinfo.asenumerable (); returnView (); }        //        //GET:/USER/DETAILS/5         PublicActionResult Details (intID) {returnView (); }        //        //GET:/user/create         PublicActionResult Create () {returnView (); }        //        //POST:/user/create[HttpPost] PublicActionResult Create (formcollection collection) {Try            {                //todo:add Insert Logic here                returnRedirecttoaction ("Index"); }            Catch            {                returnView (); }        }        //        //GET:/USER/EDIT/5         PublicActionResult Edit (intID) {returnView (); }        //        //POST:/USER/EDIT/5[HttpPost] PublicActionResult Edit (intID, formcollection collection) {            Try            {                //todo:add update logic here                returnRedirecttoaction ("Index"); }            Catch            {                returnView (); }        }        //        //GET:/USER/DELETE/5         PublicActionResult Delete (intID) {returnView (); }        //        //POST:/USER/DELETE/5[HttpPost] PublicActionResult Delete (intID, formcollection collection) {            Try            {                //Todo:add Delete logic here                returnRedirecttoaction ("Index"); }            Catch            {                returnView (); }        }    }}
automatically generate additions and deletions to search. Background.

2) Add the index list view

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 collecti On) {try {//Todo:add update logic here return Redirecttoact            Ion ("Index");            } catch {return View (); }}///GET:/USER/DELETE/5 public actionresult Delete (int id) {return Vi        EW (); }////POST:/USER/DELETE/5 [httppost] public actionresult Delete (int id, formcollection coll ection) {try {//Todo:add delete logic here return REDIRECTT            Oaction ("Index");            } catch {return View (); }        }    }}
View page (add and revise search). Front desk)

MVC automatically generates additions and deletions and changes

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.