Asp.net mvc 在asp.net mvc中将文本框类型转换为密码

Asp.net mvc 在asp.net mvc中将文本框类型转换为密码,asp.net-mvc,Asp.net Mvc,如何在asp.net mvc中将文本框类型转换为密码?您的意思是?使用HTML帮助程序功能密码: <%= Html.Password("Password") %> 请参见清单4和清单5,即第行下方的.cshtml文件中的Razor视图 @Html.PasswordFor(m=>m.Password) 这里m是模型对象,password是密码字段名。下面是基于html帮助程序的扩展: 转换前: @Html.TextBox("mypass", null, new { sty

如何在asp.net mvc中将文本框类型转换为密码?

您的意思是

使用HTML帮助程序功能
密码

<%= Html.Password("Password") %>

请参见清单4和清单5,即第行下方的.cshtml文件中的Razor视图

  @Html.PasswordFor(m=>m.Password)

这里m是模型对象,password是密码字段名。

下面是基于html帮助程序的扩展:

转换前:

@Html.TextBox("mypass", null, new { style = "width: 200px;" })
@Html.Password("mypass", null, new { style = "width:200px;" })
@Html.TextBox("mypass", null, new { @class = "" })
@Html.TextBox("mypass", null, new { @class = "", @type = password })
转换后:

@Html.TextBox("mypass", null, new { style = "width: 200px;" })
@Html.Password("mypass", null, new { style = "width:200px;" })
@Html.TextBox("mypass", null, new { @class = "" })
@Html.TextBox("mypass", null, new { @class = "", @type = password })

希望可以帮助他人。

ASP中有许多类型的使用密码输入的文本框。网络MVC

有了html控件,它就像

<input type="password" name="xx" id="yy">
@Html.Password(name, value, html_attributes)
或者在强类型视图中,您可以编写

@Html.PasswordFor(model=>model.Password)

使用强类型视图和引导时,请使用以下代码确保密码字段的样式正确:

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

@Html.PasswordFor(model=>model.Password,new{htmlAttributes=new{@class=“form control”,placeholder=“Password”})
@Html.ValidationMessageFor(model=>model.Password)
在.cshtml文件中:

@Html.PasswordFor(modal => modal.Password)

另一种方法是将
@type=password
添加到
html.texbox()
属性中,如下所示:

转换前:

@Html.TextBox("mypass", null, new { style = "width: 200px;" })
@Html.Password("mypass", null, new { style = "width:200px;" })
@Html.TextBox("mypass", null, new { @class = "" })
@Html.TextBox("mypass", null, new { @class = "", @type = password })
转换后:

@Html.TextBox("mypass", null, new { style = "width: 200px;" })
@Html.Password("mypass", null, new { style = "width:200px;" })
@Html.TextBox("mypass", null, new { @class = "" })
@Html.TextBox("mypass", null, new { @class = "", @type = password })
这将用圆圈而不是文本来屏蔽文本框文本。它这样做是因为
@type=password
属性告诉您的文本框它属于“password”类型


这种将文本框转换为密码类型的方法是从标准razor表单文本框进行转换的一种简便快捷的方法。

在asp.net mvc中将文本框类型转换为密码

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

我想我的文本框显示***当我写在密码字段,而不是普通的文本,所以是的,你应该使用上面的代码。或者,我猜这家伙正在asp.net mvc中使用razer视图。请注意,自mvc 1以来,这一直不是有效的语法,我们现在使用的是mvc 5(+),您应该使用“代码行没有上下文/解释”。请再加一些解释。为什么不加一些解释呢?在答案中添加解释始终是一种好的做法,因为这有助于OP和其他人理解你的意图。这只是重复其他人已经说过的话,多次。请不要这样做