Understand ASP. net mvc Programming Model Chapter 1 data model, asp. netmvc

Source: Internet
Author: User

Understand ASP. net mvc Programming Model Chapter 1 data model, asp. netmvc
MVC model

MVCModelContains all application logic (business logic, verification logic, data access logic), except for pure view and controller logic. Through MVC, the model can save and operate application data.

Models folder

Models folderContains classes that represent the application model.

Take logon verification as an example to createAccountModels. csFile for the application security model.

AccountModelsIncludeLogOnModel,ChangePasswordModelAndRegisterModel.

LogOnModel:

public class LogOnModel{[Required][Display(Name = "User name")]public string UserName { get; set; }[Required][DataType(DataType.Password)][Display(Name = "Password")]public string Password { get; set; }[Display(Name = "Remember me?")]public bool RememberMe { get; set; }}

RegisterModel:

public class RegisterModel{[Required][Display(Name = "User name")]public string UserName { get; set; }[Required][DataType(DataType.EmailAddress)][Display(Name = "Email address")]public string Email { get; set; }[Required][StringLength(100, ErrorMessage = "The {0} must be at least {2} characters long.", MinimumLength = 6)][DataType(DataType.Password)][Display(Name = "Password")]public string Password { get; set; }[DataType(DataType.Password)][Display(Name = "Confirm password")][Compare("Password", ErrorMessage = "The password and confirmation password do not match.")]public string ConfirmPassword { get; set; }}

ChangePasswordModel:

public class ChangePasswordModel{[Required][DataType(DataType.Password)][Display(Name = "Current password")]public string OldPassword { get; set; }[Required][StringLength(100, ErrorMessage = "The {0} must be at least {2} characters long.", MinimumLength = 6)][DataType(DataType.Password)][Display(Name = "New password")]public string NewPassword { get; set; }[DataType(DataType.Password)][Display(Name = "Confirm new password")][Compare("NewPassword", ErrorMessage = "The new password and confirmation password do not match.")]public string ConfirmPassword { get; set; }}
Add database model

InSolution Manager, Right-clickModelsFolder, selectAdd,Class.

To addMovieDB. csExample,

using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Data.Entity;namespace MvcDemo.Models{public class MovieDB{public int ID { get; set; }public string Title { get; set; }public string Director { get; set; }public DateTime Date { get; set; }}public class MovieDBContext : DbContext{public DbSet<MovieDB> Movies { get; set; } }}
Add a database Controller

Visual Studio creates the following files:

  • MoviesController. cs file in the Controllers folder
  • Movies folder in Views folder
Add database view

The following files are automatically created in the Movies Folder:

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

Related Article

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.