확실하지 예상대로 작동하지 그러나 그것은 나에게 놀람이었다 ..MVC 검증이 예상 될 경우
내가 강하게 RegistrationViewModel와보기를 입력하고,하지만 난 양식을 제출, 검증을 시도 할 때 2 곳에서 잘못 검증합니다.
- "테스트"를 입력하면 이메일 입력란에 유효성 검사 오류가 표시되지 않습니다.
- 암호 유효성 검사기는 암호가있을 때 암호가 일치하지 않는다고 말합니다.
왜 이런 일이 일어나는 지 알고 계십니까?
뷰 모델 클래스 :
public class RegistrationViewModel
{
public RegisterModel RegistrationData { get; set; }
...
}
검증 속성이 RegistrationData 클래스의 속성에 있습니다
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; }
[Required]
[Display(Name = "First name")]
[StringLength(20, ErrorMessage = "First name must be between 2 and 20 characters.", MinimumLength = 2)]
public string FirstName { get; set; }
[Required]
[Display(Name = "Last name")]
[StringLength(20, ErrorMessage = "Last name must be between 2 and 20 characters.", MinimumLength = 2)]
public string LastName { get; set; }
}
보기 :
@model PropertyManager_MVC.Areas.Account.ViewModels.RegistrationViewModel
<div class="editor-field">
@Html.TextBoxFor(m => m.RegistrationData.Email)
@Html.ValidationMessageFor(m => m.RegistrationData.Email)
</div>
<div class="editor-label">
@Html.LabelFor(m => m.RegistrationData.Password)
</div>
<div class="editor-field">
@Html.PasswordFor(m => m.RegistrationData.Password)
@Html.ValidationMessageFor(m => m.RegistrationData.Password)
</div>
<div class="editor-label">
@Html.LabelFor(m => m.RegistrationData.ConfirmPassword)
</div>
<div class="editor-field">
@Html.PasswordFor(m => m.RegistrationData.ConfirmPassword)
@Html.ValidationMessageFor(m => m.RegistrationData.ConfirmPassword)
</div>
서버 측 유효성 확인이란 무엇입니까? – Jon
아니요, 클라이언트 측 유효성 검사 – Greg
webconfig에서 클라이언트 측 유효성 검사와 눈에 잘 띄지 않는 j를 모두 사용할 수 있습니다. – Greg