MVC比较不工作 [英] MVC Compare not working
本文介绍了MVC比较不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在验证使用[比较属性2文本框的问题。即使他们是相同的客户端验证说,他们是不同的。
I'm having problems validating 2 textboxes using the [Compare-attribute. Even if they're same the client validation says they're different.
在我editmodel我有:
In my editmodel I have:
[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>
文本框被呈现为:
Textboxes gets rendered as:
<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>
什么可能是错误的/在这里丢失?
What might be wrong/missing here?
推荐答案
我更新了使用的NuGet软件包管理系统不显眼+ jQuery验证。而这奏效了。
I updated unobtrusive + jquery validation using the Nuget packagemanager. And that did the trick
这篇关于MVC比较不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文