0
[StringLength (50 , ErrorMessage = "Password: Exceeds Size")]
public string Password
{
get;
set;
}
查看:
@Html.LabelFor(m => m.Password)
@Html.PasswordFor(m => m.Password)
@{ Html.ValidateFor(m => m.Password); }
这是我的模型&看法,但密码字段不是在编辑模式填充(即;由于安全问题,无法将DB的密码值分配给此密码字段)。但不显眼的JavaScript验证工作正常。由于我们有编辑问题,因为我googled我有解决方案来替换视图如下;
@Html.LabelFor(m => m.Password)
<input type="password" name="Password" id="Password" value="@Model.Password" />
@{ Html.ValidateFor(m => m.Password); }
但是,这并没有提高我在模型中所需的验证集。还发现由于data-val属性没有绑定,因此不显眼的JS验证不适用于此密码字段。
所有其他验证工作正常。我能解决这个问题吗?
使用'@ Html.TextBoxFor(m => m.Password,new {type =“password”})''。但是为什么'PasswordFor()'没有设置该值是有原因的(为了安全起见,你应该尽量减少传递密码的次数) –
谢谢,这将解决我的问题。由于这是给予管理员,它被加密。我可以继续解决。 – pvaju896
[Repopulate html.passwordFor]可能的重复(http://stackoverflow.com/questions/9491655/repopulate-html-passwordfor) – Liam