<tr>
<th class="editAddLabel">@Html.LabelFor(model => model.loginVM.password, "Password:")</th>
<td class="editAddField">@Html.PasswordFor(model => model.loginVM.password, new { maxlength = "20" })
<div class="error">
@Html.ValidationMessageFor(model => model.loginVM.password)
</div>
</td>
</tr>
<tr>
<th class="editAddLabel">@Html.LabelFor(model => model.loginVM.password, "Confirm Password:")</th>
<td class="editAddField">@Html.Password("ConfirmPassword", new { maxlength = "20" })
</td>
</tr>这是我现在的视图,由于某种原因,当我转到我的页面注册用户时,确认密码文本框中充满了一堆星号。我不能想象星号代表一个值,因为我的模型还没有添加任何东西。有没有人能告诉我怎么才能让这个字段变成空的?
发布于 2015-07-21 23:44:39
这是您的浏览器为您填写的已保存的密码。如果要禁用该功能,则需要对输入应用autocomplete="off":
@Html.Password("ConfirmPassword", new { maxlength = "20", autocomplete = "off })发布于 2015-07-22 11:37:40
这是因为Html.Password将第二个参数视为字段值。所以您的代码@Html.Password("ConfirmPassword", new { maxlength = "20" })将'{ maxlength = "20" }'作为初始值传递给您的字段。
这是您的代码生成的HTML标记...请注意该值。
<input id="ConfirmPassword"
name="ConfirmPassword"
type="password"
value="{ maxlength = 20 }">如果您更改了Chrome中的超文本标记语言(使用开发人员工具),并删除了type="password",您将看到该字段中的值为明文。
我建议使用Html.PasswordFor,这就是您对other password字段所做的操作。它消除了为属性名称指定字符串的需要。
https://stackoverflow.com/questions/31543681
复制相似问题