asp.net-mvc 在 asp.net mvc 中将文本框类型转换为密码
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2897160/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Convert textbox type to password in asp.net mvc
提问by Fraz Sundal
How do I convert a textbox type to password in asp.net mvc?
如何在 asp.net mvc 中将文本框类型转换为密码?
采纳答案by Palantir
You mean <%=Html.Password("test")%>
?
你的意思是<%=Html.Password("test")%>
?
回答by Ravinder Gangadher
Just write in Razor View i.e. in .cshtml file below line
只需在 Razor View 中写入 .cshtml 文件
@Html.PasswordFor(m=>m.Password)
Here m is model object and password is the password field name.
这里 m 是模型对象,密码是密码字段名称。
回答by ChrisF
回答by Cengiz Araz
There are many types of using password-typed textboxes in ASP. NET MVC
在 ASP 中有许多使用密码类型文本框的类型。网络MVC
With html controls it would be like;
使用 html 控件就像;
<input type="password" name="xx" id="yy">
With Razor-syntax it would be like;
使用 Razor 语法就像;
@Html.Password(name, value, html_attributes)
Or in a strongly typed view you could write
或者在强类型视图中,您可以编写
@Html.PasswordFor(model=>model.Password)
回答by Sven Vranckx
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" })
回答by shaijut
below is extention based on html helper:
下面是基于 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.
希望能帮助某人。
回答by Yogesh Singh Rawat
<div class="editor-field">
@Html.PasswordFor(model => model.Password, new { htmlAttributes = new { @class = "form-control", placeholder = "Password" } })
@Html.ValidationMessageFor(model => model.Password)
</div>
回答by Rajan Shrestha
In .cshtml file:
在 .cshtml 文件中:
@Html.PasswordFor(modal => modal.Password)
回答by Joey Phillips
Another way is to add @type = password
to your html.texbox()
attributes like so:
另一种方法是添加@type = password
到您的html.texbox()
属性中,如下所示:
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".
这将用圆圈而不是文本来掩盖您的文本框文本。它这样做,因为该@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.
这种将文本框转换为输入密码的方法是一种从标准剃刀表单文本框进行转换的简单快捷的方法。
回答by Test
@Html.EditorFor(model => model.Password,
"Password",
new { htmlAttributes = new { @class = "form-control" } })