Convert textbox type to password in asp.net mvc
How do I convert a textbox type to p开发者_C百科assword in asp.net mvc?
Just write in Razor View i.e. in .cshtml file below line
@Html.PasswordFor(m=>m.Password)
Here m is model object and password is the password field name.
You mean <%=Html.Password("test")%>
?
Either use the HTML helper function Password
:
<%= Html.Password("Password") %>
or use the type
parameter on an input field:
<input name="password" type="password" />
See listings 4 and 5 on this page
There are many types of using password-typed textboxes in ASP. NET MVC
With html controls it would be like;
<input type="password" name="xx" id="yy">
With Razor-syntax it would be like;
@Html.Password(name, value, html_attributes)
Or in a strongly typed view you could write
@Html.PasswordFor(model=>model.Password)
When using a strong-typed view and bootstrap, use the following code to make sure the password field is properly styled:
@Html.PasswordFor(model => model.Password, new { @class = "form-control" })
below is extention based on html helper:
before converting:
@Html.TextBox("mypass", null, new { style = "width: 200px;" })
After converting:
@Html.Password("mypass", null, new { style = "width:200px;" })
hope helps someone.
<div class="editor-field">
@Html.PasswordFor(model => model.Password, new { htmlAttributes = new { @class = "form-control", placeholder = "Password" } })
@Html.ValidationMessageFor(model => model.Password)
</div>
In .cshtml file:
@Html.PasswordFor(modal => modal.Password)
Another way is to add @type = password
to your html.texbox()
attributes like so:
before converting:
@Html.TextBox("mypass", null, new { @class = "" })
After converting:
@Html.TextBox("mypass", null, new { @class = "", @type = password })
This will mask your text box text with circles instead of text. It does this, because the @type = password
attribute tells your text box that it is of type "password".
This method of converting your text box to type password is an easy quick way to to make the conversion from your standard razor form text box.
@Html.EditorFor(model => model.Password,
"Password",
new { htmlAttributes = new { @class = "form-control" } })
Convert textbox type to password in asp.net mvc
@Html.EditorFor(model => model.Password, new { htmlAttributes = new { @class = "form-control", placeholder = "Password", @type="Password" } })
精彩评论