Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Model does not apply DataType.Password

Instead of using the object directly, on a simple Razor View I have a form using as it+s model a decorator object.

public class GlobalAccount
{
    public GlobalAccount()
    {
        this.TestService = new TestServiceModel();
    }

    public TestServiceModel TestService { get; set; }
}

beeing TestServiceModel represented as

public class TestServiceModel
{
    [Required]
    [Display(Name = "Endpoint (url of your service like http://mydomain/remote/)")]
    public string Endpoint { get; set; }

    [Required]
    [Display(Name = "System username")]
    public string UserName { get; set; }

    [Required]
    [DataType(DataType.Password)]
    [Display(Name = "System password")]
    public string Password { get; set; }
}

Note the Password property decorated with DataType.Password

and in a Partial Razor view I have a call to that object

@model OnlineServices.Administration.Models.GlobalAccount
...
@Html.TextBoxFor(model => model.TestService.Password, new { size = "30" })

problem is that, in the html I get type="text" instead of text="password"

You can see in this image the entire flow:

enter image description here

What am I missing here?

like image 950
balexandre Avatar asked May 18 '11 12:05

balexandre


1 Answers

You should use Html.Password, or even better use Html.EditorFor which will read the DataType.Password and output a password type input for you.

The Html.TextBoxFor is just text based input, not as password based one.

like image 78
Kieron Avatar answered Nov 16 '22 00:11

Kieron