<1>
Home Controller
Using system;using system.collections.generic;using system.data;using system.data.entity;using System.Linq;using System.web;using system.web.mvc;using mvcapplication4.models;namespace mvcapplication4.controllers{public class Homecontroller:controller {private SalesEntities db = new SalesEntities ();//salesentities is an ADO Entity Data Model class GET:/home/public actionresult Index () {return View (db. T_userinfo.tolist ()); }///GET:/HOME/DETAILS/5 public actionresult Details (int id = 0) {T_userinfo T _userinfo = db. T_userinfo.single (t = t.id = = ID); if (T_userinfo = = null) {return httpnotfound (); } return View (T_userinfo); }///GET:/home/create public ActionResult Create () {return View (); }////POST:/home/create [httppost] public ActionresulT Create (T_userinfo t_userinfo) {if (modelstate.isvalid) {db. T_userinfo.addobject (T_userinfo); Db. SaveChanges (); Return redirecttoaction ("Index"); } return View (T_userinfo); }///GET:/HOME/EDIT/5 public actionresult Edit (int id = 0) {T_userinfo t_useri NFO = db. T_userinfo.single (t = t.id = = ID); if (T_userinfo = = null) {return httpnotfound (); } return View (T_userinfo); }////POST:/HOME/EDIT/5 [httppost] public actionresult Edit (T_userinfo t_userinfo) { if (modelstate.isvalid) {db. T_userinfo.attach (T_userinfo); Db. Objectstatemanager.changeobjectstate (T_userinfo, entitystate.modified); Db. SaveChanges (); Return redirecttoaction ("Index"); } Return View (T_userinfo); }///GET:/HOME/DELETE/5 public actionresult Delete (int id = 0) {T_userinfo T_u Serinfo = db. T_userinfo.single (t = t.id = = ID); if (T_userinfo = = null) {return httpnotfound (); } return View (T_userinfo); }////POST:/HOME/DELETE/5 [HttpPost, ActionName ("Delete")] public ActionResult Deleteconfir Med (int id) {T_userinfo t_userinfo = db. T_userinfo.single (t = t.id = = ID); Db. T_userinfo.deleteobject (T_userinfo); Db. SaveChanges (); Return redirecttoaction ("Index"); } protected override void Dispose (bool disposing) {db. Dispose (); Base. Dispose (disposing); } }}
Index view (This is the first page)
@model ienumerable<mvcapplication4.models.t_userinfo>@{viewbag.title = "Index";}
CREATE view
@model mvcapplication4.models.t_userinfo@{viewbag.title = "Create";}
Delete View
@model mvcapplication4.models.t_userinfo@{ viewbag.title = "Delete";}
Details view
@model mvcapplication4.models.t_userinfo@{ viewbag.title = "Details";}
Edit View
@model mvcapplication4.models.t_userinfo@{viewbag.title = "Edit";}
MVC [Control and view interaction]