RegisterViewModel.cs

public class RegisterViewModel { [Required] [EmailAddress] [Display(Name = "Email")] public string Email { get; set; } [Required] [StringLength(100, ErrorMessage = "The {0} must be at least {2} and at max {1} 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; } }
A pattern used by the Visual Studio team creates a set of simple classes with no complex types that consist of nothing but public properties and data annotations. To see an example of this pattern, create a new ASP.NET Core Web Application project using the Web Application template and change the authentication type to individual user accounts. The project template includes a Models folder with a subfolder called AccountViewModels. The AccountViewModels folder contains a class called RegisterViewModel.cs. The RegisterViewModel has only enough properties to support the view that it is used with. Each property is decorated with a set of data annotations. These attributes—when used with the HTML Helpers or Tag Helpers—automatically generate the HTML needed to support form validation using jQuery validation. Shows RegisterViewModel.

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.