Ich lege eine Ansicht aus, die zwei Kennwortzeichenfolgen vergleicht. Die beiden Eigenschaften in einem meiner Modelle sind ziemlich einfach:Clientseitige Validierung für CompareAttribute DataAnnotation nicht ausgelöst
[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; }
Hier ist meine Ansicht Code:
<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>
Alle Attribute feuern ihre clientseitige Nachrichten Validierung, wenn getestet, mit Ausnahme der CompareAttribute auf ConfirmPassword, das nicht ausgelöst wird, bis ich den Server treffe. In meinem Controller ist jedoch ModelState.IsValid = false.
Ich verglich, was ich mache, mit der Standard-MVC-Anwendung, die korrekt funktioniert. Irgendwelche Vorschläge zur Fehlerbehebung und zur Behebung?
Ich benutze MVC 3 RTM.
Das war es. Du hast tatsächlich zwei Probleme gelöst, die ich hatte. http://stackoverflow.com/questions/4752877/remote-validation-in-asp-net-mvc-3-how-to-use-additionalfields-in-action-method Wenn Sie dort drüben gehen und eine Antwort hinzufügen, die auf zeigt Diese Frage werde ich dir auch dort beantworten. DANKE! – beaudetious