Html.PasswordFor is not populated?

点点圈 提交于 2019-12-22 11:06:04

问题


I spend a lot of my time, trying to understand why in a razor expression of

@HTML.PasswordFor( m => m.Password)

I can't set the value from the model the only solution that I found it's injecting the value by html properties like this

@HTML.PasswordFor( m => m.Password, new { value = Model.Password })

Am I doing something wrong?? is the correct helper?? this is the field model configuration

[Required(ErrorMessage = "La contraseña es obligatoria.")]
[StringLength(100, ErrorMessage = "El {0} debe tener al menos {2} caracteres de longitud.", MinimumLength = 6)]
[DataType(DataType.Password)]
[Display(Name = "Contraseña")]
public string Password { get; set; }

It's the only solution?


回答1:


It's a security feature. To make this work implies that a) you are able to access the users password in plain text and b) are transmitting it over the wire to their browser.

Neither of which are safe and shouldn't be encouraged.

As such, this is a feature of Razor, rather than an issue.



来源:https://stackoverflow.com/questions/9491655/html-passwordfor-is-not-populated

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!