如何获取密码 html 帮助程序以在验证失败时呈现密码
我有一个用于创建新帐户的表单,其中有一个密码字段。我使用视图模型将数据传递到控制器操作并返回到表单视图。当用户输入详细信息并单击“提交”时,如果验证失败并且将它们返回到在视图模型中传回的同一视图,则不会将密码默认为他们输入的内容。
我怎样才能让它做到这一点?或者我应该尝试一下吗?
I have a form for creating a new account and it has a password field in it. I'm using view models to pass data to the controller action and back to the form view. When the user enters their details in, and clicks submit, if validation fails and it returns them to the same view passing back in the view model, it won't default the password to what they entered.
How can I get it to do this? Or should I even try?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以通过显式调用在验证后设置密码:
至于动机,我在网络上看到了这两种行为,但可能我会选择将密码留空并让用户重新输入密码,因此保留密码助手行为是。
You can set the password after validation by explicitly calling:
As for motivation I've seen both behaviours in the web, but probably I would choose to leave the password empty and make the user retype the password, hence leaving the Password Helper behaviour as it is.