MVC [Control and view interaction]

Source: Internet
Author: User
Tags actionlink

<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]

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.