Getting Started with MVC--increasing

Source: Internet
Author: User

Create a database table as follows:

Generate EF Models

------------------------------------------------------------------------------//<auto-generated>//    This code is generated based on the template.    manually changing this file may cause unexpected behavior in the application.    If the code is regenerated, manual changes to this file will be overwritten. </auto-generated>//------------------------------------------------------------------------------ namespace mvcapplicationstudy.models{    using System;    Using System.Collections.Generic;        public partial class UserInfo    {public        int ID {get; set;}        public string UserName {get; set;}        public string Userpwd {get; set;}        Public System.DateTime regtime {get; set;}}    }

Create a controller HomeController

Using system;using system.collections.generic;using system.linq;using system.web;using System.Web.Mvc;using        Mvcapplicationstudy.models;namespace mvcapplicationstudy.controllers{public class Homecontroller:controller { GET:/home/public actionresult Index ()//Register page {if (!string.            IsNullOrEmpty (request["MSG"])) {viewbag.msg = request["MSG"];        } return View ();            The public ActionResult Register ()//Gets the parameter {UserInfo UserInfo = new UserInfo () from the form; Userinfo.username = request["Txtname"].            ToString (); Userinfo.userpwd = request["Txtpwd"].            ToString ();            Userinfo.regtime = DateTime.Now;            Testentities dbentity = new Testentities ();            DBENTITY.USERINFO.ADD (UserInfo); if (dbentity.savechanges () > 0) {return redirecttoaction ("Index", "Home", new {msg = "Registration succeeded"                }); Return COntent ("registered success");            } else {return redirecttoaction ("Index", "Home", new {msg= "registration failed"});        }}//The Name property of the form element in the form is automatically populated with the same value as the parameter in the current method.            Public ActionResult Register2 (string txtname, String txtpwd) {UserInfo UserInfo = new UserInfo ();            Userinfo.username = txtname;            Userinfo.userpwd = txtpwd;            Userinfo.regtime = DateTime.Now;            Testentities dbentity = new Testentities ();            DBENTITY.USERINFO.ADD (UserInfo);            if (dbentity.savechanges () > 0) {return Content ("registered successfully");            } else {return Content ("registration failed"); }}//AutoFill (if the Name property of the form element in the form matches the name of the attribute in the entity class, it is automatically populated.)        )/*public ActionResult Register3 (UserInfo UserInfo) {userinfo.regtime = DateTime.Now;        Testentities dbentity = new Testentities (); DBENTITY.USERINFO.ADD (USerinfo);        if (dbentity.savechanges () > 0) {return Content ("registered successfully");        } else {return Content ("registration failed"); }    }*/    }}

Add an index view

@{    Layout = null;} <! DOCTYPE html>

The build page is as follows

Getting Started with MVC--increasing

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.