Model class
[Required(ErrorMessage = "Pass word is required")]
//[ValidatePasswordLength]
[DataType(DataType.Password)]
//[Display(Name = "Password")]
public string Password { get; set; }
view
<div class="editor-label">
@Html.LabelFor(model => model.Password)
</div>
<div class="editor-field">
@Html.TextBoxFor(model => model.Password, new {@class="form-control",placeholder="Password" })
@Html.ValidationMessageFor(model => model.Password)
</div>
I googled it.I found to use @html.Editor
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?
IMO the main difference is that Textbox is not strongly typed. TextboxFor take a lambda as a parameter that tell the helper the with element of the model to use in a typed view. You can do the same things with both, but you should use typed views and TextboxFor when possible.
it's absolutly wrong answer, becuase the key difference is that Texbox returns input and editorfor returns your template where input is default template for editorfor.
The TextBoxes can be made ReadOnly by setting the HTML ReadOnly attribute using the HtmlAttributes parameter in Html. TextBox and Html. TextBoxFor helper functions. Note: For beginners in ASP.Net MVC, please refer my article ASP.Net MVC Hello World Tutorial with Sample Program example.
TextBoxFor represents a single-line input control that allows end-users to enter text.
If your MVC version is new enough, then
@Html.EditorFor(model => model.Password, new { htmlAttributes = new {@class="form-control", placeholder="Password"}})
Otherwise
@Html.PasswordFor(model => model.Password, new {@class="form-control", placeholder="Password"})
You can still use @Html.TextBoxFor:
@Html.TextBoxFor(model => model.Password, new {@class="form-control", placeholder="Password", @type = "password" })
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