product.Name) %>
我需要生成的输出设置autocomplete =“off”属性.
我错过了什么?
编辑:
我正在寻找一个接受属性的键/值字典的EditorFor的扩展方法,所以我可以像这样调用它: product.Name,new {autocomplete =“off”} )%>
这是为LabelFor完成的,但需要针对EditorFor进行调整
public static MvcHtmlString LabelFor(this HtmlHelper html, Expression> expression, object htmlAttributes) {
return LabelFor(html, expression, new RouteValueDictionary(htmlAttributes));
}
public static MvcHtmlString LabelFor(this HtmlHelper html, Expression> expression, IDictionary htmlAttributes)
{
ModelMetadata metadata = ModelMetadata.FromLambdaExpression(expression, html.ViewData);
string htmlFieldName = ExpressionHelper.GetExpressionText(expression);
string labelText = metadata.DisplayName ?? metadata.PropertyName ?? htmlFieldName.Split('.').Last();
if (String.IsNullOrEmpty(labelText))
{
return MvcHtmlString.Empty;
}
TagBuilder tag = new TagBuilder("label");
tag.MergeAttributes(htmlAttributes);
tag.Attributes.Add("for", html.ViewContext.ViewData.TemplateInfo.GetFullHtmlFieldId(htmlFieldName));
tag.SetInnerText(labelText);
return MvcHtmlString.Create(tag.ToString(TagRenderMode.Normal));
}
EDIT2:
我意识到它不能命名为EditorFor,因为已经存在一个被覆盖的EditorFor,它接受一个匿名类型,请看这里http://msdn.microsoft.com/en-us/library/ff406462.aspx ..无论如何,我们可以用不同的名字命名,没有大人物.