Understanding the MVC programming model in ASP. 3rd Data Model

Source: Internet
Author: User

MVC model

The MVC model contains all the application logic (business logic, validation logic, data access logic), in addition to pure view and controller logic. With MVC, models can save and manipulate application data.

Models folder

The Models folder contains classes that represent the application model.

Take login verification as an example to create a AccountModels.cs file for the application security model.

accountmodels contains logonmodel,Changepasswordmodel , and Registermodel.

Logonmodel:

 Public classLogonmodel{[required][display (Name="User name")] Public stringUserName {Get;Set; } [Required] [DataType (Datatype.password)] [Display (Name="Password")] Public stringPassword {Get;Set; } [Display (Name="Remember me?")] Public BOOLRememberMe {Get;Set; }}

Registermodel:

 Public classRegistermodel{[required][display (Name="User name")] Public stringUserName {Get;Set; } [Required] [DataType (Datatype.emailaddress)] [Display (Name="Email Address")] Public stringEmail {Get;Set; } [Required] [Stringlength ( -, errormessage ="The {0} must is at least {2} characters long.", Minimumlength=6)][datatype (Datatype.password)][display (Name="Password")] Public stringPassword {Get;Set; } [DataType (Datatype.password)] [Display (Name="Confirm Password")][compare ("Password", errormessage ="The password and confirmation password DoNot match.")] Public stringConfirmPassword {Get;Set; }}

Changepasswordmodel:

 Public classChangepasswordmodel{[required][datatype (Datatype.password)][display (Name="Current Password")] Public stringOldPassword {Get;Set; } [Required] [Stringlength ( -, errormessage ="The {0} must is at least {2} characters long.", Minimumlength=6)][datatype (Datatype.password)][display (Name="New Password")] Public stringNewPassword {Get;Set; } [DataType (Datatype.password)] [Display (Name="Confirm New Password")][compare ("NewPassword", errormessage ="The new password and confirmation password DoNot match.")] Public stringConfirmPassword {Get;Set; }}
Add a Database model

In solution Manager , right-click the Models folder and select Add , class .

To add MovieDB.cs as an example ,

usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingsystem.web;usingSystem.Data.Entity;namespacemvcdemo.models{ Public classmoviedb{ Public intID {Get;Set; } Public stringTitle {Get;Set; } Public stringDirector {Get;Set; } PublicDateTime Date {Get;Set; }} Public classmoviedbcontext:dbcontext{ PublicDbset<moviedb> Movies {Get;Set; } }}
Adding a Database controller
    1. In Solution Explorer, right-click the Controllers folder and select Add, Controller.
    2. Set the controller name to Moviescontroller
    3. Select Template: Controller with read/write actions and views, using Entity Framework
    4. Select Model class: Moviedb (Mvcdemo.models)
    5. Select data Context class: Moviedbcontext (Mvcdemo.models)
    6. Select View Razor (CSHTML)
    7. Click Add

Visual Studio creates the following files:

    • MoviesController.cs files in the Controllers folder
    • The Movies folder in the Views folder
To add a database view

The following files are automatically created in the Movies folder:

    • Create.cshtml
    • Delete.cshtml
    • Details.cshtml
    • Edit.cshtml
    • Index.cshtml

Understanding the MVC programming model in ASP. 3rd Data Model

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.