<%= Html.EditorFor(product => product.Name) %>
J'ai besoin que la sortie générée ait un ensemble d'attributs autocomplete = "off".Comment désactiver la saisie semi-automatique du champ de saisie avec EditorFor?
Qu'est-ce qui me manque?
Edit: Je suis à la recherche d'une méthode d'extension pour EditorFor qui accepte le dictionnaire clé/valeur pour les attributs, donc je peux l'appeler comme ceci: <%= Html.EditorFor(product => product.Name, new { autocomplete = "off" }) %>
Ici, il est fait pour LabelFor, mais il est nécessaire pour être ajusté pour 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: je l'ai réalisé ne peut pas être nommé EditorFor parce qu'il existe déjà une EditorFor surchargée qui accepte un type anonyme, voir ici http://msdn.microsoft.com/en-us/library/ff406462.aspx .. de toute façon, nous pouvons le nommer différemment, non biggies.
Nous devons obtenir la valeur actuelle, si elle a un ensemble, en quelque sorte . – randomguy