<%= Html.EditorFor(product => product.Name) %>
我需要生成的输出具有autocomplete =“off”属性集。如何使用EditorFor禁用输入字段的自动完成功能?
我失踪了什么?
编辑: 我在寻找EditorFor接受键/值字典属性的扩展方法,这样我就可以这样调用:<%= Html.EditorFor(product => product.Name, new { autocomplete = "off" }) %>
这是为LabelFor完成,但它是需要对于EditorFor
public static MvcHtmlString LabelFor<TModel, TValue>(this HtmlHelper<TModel> html, Expression<Func<TModel, TValue>> expression, object htmlAttributes) {
return LabelFor(html, expression, new RouteValueDictionary(htmlAttributes));
}
public static MvcHtmlString LabelFor<TModel, TValue>(this HtmlHelper<TModel> html, Expression<Func<TModel, TValue>> expression, IDictionary<string, object> 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 ..反正,我们可以以不同的名字,没有BIGGIES。
我们需要获取当前值,如果它有一个集合, 。 – randomguy 2010-07-22 13:05:14