わからない期待通りに動作していないが、それは私には驚きでした。..MVCの検証は、これが予想される場合
は、私は強くRegistrationViewModelとの見解を入力していますが、私は、フォームを送信するために、検証をしようとすると、 2か所で間違って検証されます。
- 「テスト」と入力すると電子メールフィールドで検証エラーが発生しません。
- パスワードバリデーターには、パスワードが一致しないと書かれています。
これはなぜ起こっているのですか?
のViewModelクラス:
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
クライアント側の検証と目立たないjは両方ともwebconfigで有効です。 – Greg