Why does not the [DataType (DataType.Password)] work for me?

0

I have a model CredencialesViewModel which has a property Pwd type string add the decorator type data, but in the view does not render a input type password if not that one type text. / p>

Why will this be?

    
asked by vcasas 12.06.2018 в 21:43
source

1 answer

1

If you define the ViewModel in the following way

[Required(ErrorMessage = "Pass word is required")]
[DataType(DataType.Password)]
public string Password { get; set; }

According to your MVC version, if it's newer, you should, just use @EditorFor() .

@Html.EditorFor(model => model.Password, new { htmlAttributes = new {@class="form-control", placeholder="Password"}})

and in case it's a little older

@Html.PasswordFor(model => model.Password, new {@class="form-control", placeholder="Password"})

This response is based on this StackOverflow publication in English.

Greetings and successes!

    
answered by 12.06.2018 / 21:53
source