<%= Html.EditorFor(product => product.Name) %>
Tôi cần đầu ra được tạo để có tập hợp thuộc tính tự động điền "tắt".Làm cách nào để vô hiệu hóa tính năng tự động hoàn thành của trường đầu vào bằng EditorFor?
Tôi đang thiếu gì?
Edit: Tôi đang tìm một phương pháp mở rộng cho EditorFor chấp nhận từ điển chìa khóa/giá trị cho các thuộc tính, vì vậy tôi có thể gọi nó như thế này: <%= Html.EditorFor(product => product.Name, new { autocomplete = "off" }) %>
Ở đây nó được thực hiện cho LabelFor, nhưng nó là cần thiết để được điều chỉnh cho 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: tôi nhận ra nó không thể được đặt tên EditorFor vì đã có tồn tại một EditorFor ghi đè chấp nhận một loại vô danh, xem tại đây http://msdn.microsoft.com/en-us/library/ff406462.aspx .. dù sao, chúng ta có thể đặt tên cho nó khác nhau, không có biggies.
Chúng ta cần lấy giá trị hiện tại, nếu nó có một bộ, bằng cách nào đó . – randomguy