这是设计使然Html.Password
and Html.PasswordFor
助手,不幸的是它无法更改,因为它是在助手本身中硬编码的:
public static MvcHtmlString PasswordFor<TModel, TProperty>(this HtmlHelper<TModel> htmlHelper, Expression<Func<TModel, TProperty>> expression, IDictionary<string, object> htmlAttributes)
{
if (expression == null)
{
throw new ArgumentNullException("expression");
}
object obj2 = null;
IDictionary<string, object> dictionary = htmlAttributes;
return PasswordHelper(htmlHelper, ModelMetadata.FromLambdaExpression<TModel, TProperty>(expression, htmlHelper.ViewData), ExpressionHelper.GetExpressionText(expression), obj2, dictionary);
}
看到这个object obj2 = null;
在那边?
如果你想改变这种行为,你可以使用TextBoxFor
帮助程序生成您的密码字段:
@Html.TextBoxFor(x => x.Password, new { type = "password" })