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