Getting Started with MVC--edit page

Source: Internet
Author: User

Add Action Edituserinfo

Using system;using system.collections.generic;using system.linq;using system.web;using System.Web.Mvc;using         Mvcapplicationstudy.models;namespace mvcapplicationstudy.controllers{public class Userinfocontroller:controller { GET:/userinfo/public actionresult Index () {testentities db = new Testenti            Ties (); var userinfolist = db.            Userinfo.where<userinfo> (c = true);           list<userinfo> list = Userinfolist.tolist ();            Viewbag.model = list;            return View ();        return View (list); }//Show a data detail public actionresult showdetail (int id) {Testentities db = new Testentities            (); UserInfo UserInfo = db. userinfo.where<userinfo> (U = u.id = = ID).            Singleordefault ();            if (userInfo! = null) {return View (userInfo);     } else {return Content ("parameter Error");       }} public ActionResult edituserinfo (int id) {Testentities db = new Testentities ()            ; UserInfo UserInfo = db. userinfo.where<userinfo> (U = u.id = = ID).            FirstOrDefault ();            if (userInfo! = null) return View (UserInfo);        else return Content ("parameter Error"); } [HttpPost] public actionresult edituserinfo (UserInfo UserInfo) {testentities db = new T            Estentities (); Db. Entry<userinfo> (UserInfo).            state = System.Data.EntityState.Modified; Db.           SaveChanges ();        Return redirecttoaction ("Index"); }       }}

Add View

@model mvcapplicationstudy.models.userinfo@{Layout = null;} <! DOCTYPE html>

Click Edit to run the results

Getting Started with MVC--edit page

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.