I was under the impression that using an annotation like this:
<Required()>
<DisplayName("Choose a Password:")>
<ValidatePasswordLength()>
<DataType(DataType.Password)>
Public Property Password As String
Would create a masked field when used in the view:
<%: Html.TextBoxFor(Function(model) model.Password) %>
<%: Html.ValidationMessageFor(Function(model) model.Password) %>
However this is rendered without the type="password"
What is the "DataType.Password" used for if not this?
You are using Html.TextBoxFor
which always outputs an <input type="text">
tag in the resulting HTML.
If you want the DataType.Password annotation to be automatically honored you should use Html.EditorFor
instead.
You can read more about editor templates and how to customize them here: http://bradwilson.typepad.com/blog/2009/10/aspnet-mvc-2-templates-part-1-introduction.html
TextBoxFor
overrides your annotation because it indicates a clear text input. As marcind mentioned, EditorFor
honors the annotation or you could use PasswordFor
for that field.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With