King_Fisher King_Fisher - 2 months ago 41
ASP.NET (C#) Question

Create Password field @html.TextBoxFor

Model class

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


<div class="editor-label">
@Html.LabelFor(model => model.Password)
<div class="editor-field">
@Html.TextBoxFor(model => model.Password, new {@class="form-control",placeholder="Password" })
@Html.ValidationMessageFor(model => model.Password)


I googled it.I found to use
instead of @html.TextBoxFor but i have to apply css for textbox .

I used
@Html.TextBoxFor(model => model.Password, new {@class="form-control",placeholder="Password" })
but css not applied.
How do i achieve this?


If your MVC version is new enough, then

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


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