King_Fisher King_Fisher - 1 year ago 166
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?

Answer Source

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"})
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download