Annotation xác thực trong ASP.NET MVC là gì?
Annotation xác thực trong ASP.NET MVC là gì?
Validation annotations (System.ComponentModel.DataAnnotations) là attribute khai báo quy tắc kiểm tra dữ liệu trên model/ ViewModel.
public class RegisterViewModel
{
[Required(ErrorMessage = "Tên là bắt buộc")] [StringLength(50, MinimumLength = 2)] public string Name { get; set; }
[Required, EmailAddress] public string Email { get; set; }
[Range(18, 120)] public int Age { get; set; }
[RegularExpression(@"^\d{10}$")] public string Phone { get; set; }
[DataType(DataType.Password), MinLength(8)] public string Password { get; set; }
[Compare("Password")] public string ConfirmPassword { get; set; }
[Remote("IsEmailAvailable", "Account")] public string UniqueEmail { get; set; } // kiểm tra phía server qua AJAX
Đăng nhập để tham gia thảo luận cùng mọi người.
Chưa có bình luận nào
Hãy là người đầu tiên chia sẻ suy nghĩ của bạn.