我在使用[Compare-attribute]验证2个文本框时遇到问题。即使它们是相同的,客户验证也表明它们是不同的。
在我的编辑模型中,我有:
[Required]
[DataType(DataType.Password)]
public string Password { get; set; }
[DataType(DataType.Password)]
[Compare("Password", ErrorMessage = "Password not matching")]
public string ConfirmPassword { get; set; }
在视图中:
<tr>
<td class="editor-label">
@Html.LabelFor(model => model.User.Password):
</td>
<td class="editor-field">
@Html.EditorFor(model => model.User.Password)
@Html.ValidationMessageFor(model => model.User.Password)
</td>
</tr>
<tr>
<td class="editor-label">
@Html.LabelFor(model => model.User.ConfirmPassword):
</td>
<td class="editor-field">
@Html.EditorFor(model => model.User.ConfirmPassword)
@Html.ValidationMessageFor(model => model.User.ConfirmPassword)
</td>
</tr>
文本框呈现为:
<input class="text-box single-line password" data-val="true"
data-val-required="Password missing" id="User_Password"
name="User.Password" type="password" value="" />
<input class="text-box single-line password" data-val="true"
data-val-equalto="Password not matching"
data-val-equalto-other="*.Password" id="User_ConfirmPassword"
name="User.ConfirmPassword" type="password" value="" />
<span class="field-validation-valid" data-valmsg-for="User.ConfirmPassword"
data-valmsg-replace="true"></span>
这里可能有什么问题/遗失?
答案 0 :(得分:0)
我使用Nuget packagemanager更新了unobtrusive + jquery验证。这就是诀窍