2つのパスワード文字列を比較するビューをレイアウトしています。私のモデルの一つで二つの特性は非常に簡単です:CompareAttribute DataAnnotationのクライアント側の検証が実行されない
[Required]
[RegularExpression(@"(\S)+", ErrorMessage = "White space is not allowed")]
[StringLength(20, MinimumLength = 6)]
[DataType(DataType.Password)]
[Display(Name = "New Password")]
public string NewPassword { get; set; }
[Required]
[DataType(DataType.Password)]
[RegularExpression(@"(\S)+", ErrorMessage = "White space is not allowed")]
[StringLength(20, MinimumLength = 6)]
[Display(Name = "Confirm Password")]
[Compare("NewPassword", ErrorMessage = "The new password and confirmation password do not match.")]
public string ConfirmPassword { get; set; }
ここに私のビューのコードは次のとおりです。
<table class="fieldset center" width="400">
<tbody>
<tr>
<th width="150">
@Html.LabelFor(m => m.NewPassword)
</th>
<td>
@Html.PasswordFor(m => m.NewPassword, new { @class = "itext3" })
<br /><br />@Html.ValidationMessageFor(m => m.NewPassword)
</td>
</tr>
<tr>
<th width="150">
@Html.LabelFor(m => m.ConfirmPassword)
</th>
<td>
@Html.PasswordFor(m => m.ConfirmPassword, new { @class = "itext3" })
<br /><br />@Html.ValidationMessageFor(m => m.ConfirmPassword)
</td>
</tr>
</tbody>
</table>
CompareAttribute上を除いて、試験した場合、属性のすべてが彼らのクライアント側の検証メッセージを発射しますConfirmPasswordはサーバーに到達するまで起動しません。しかし、私のコントローラでは、ModelState.IsValid = falseです。
私が行っていることを正しく動作しているデフォルトのMVCアプリケーションと比較しました。トラブルシューティングとこれを修正するための提案はありますか?
私はMVC 3 RTMを使用しています。
それはそれだった。あなたは実際に私が持っていた2つの問題を解決しました。 http://stackoverflow.com/questions/4752877/remote-validation-in-asp-net-mvc-3-how-to-use-additionalfields-in-action-methodあなたがそこに行って、この質問、私はあなたにも答えをあげます。ありがとうございました! – beaudetious