Я пытаюсь учиться на чужом коде. Я видел следующее:
@Html.TextBoxFor(m => m.Name, Html.AttributesFor(m => m.Name))
Может кто-нибудь объяснить мне, как работает Html.AttributesFor? Что это за атрибуты и где я могу их настроить.
Обновление:
Я нашел следующее скрытое в коде:
public static IDictionary<string, object> AttributesFor<TModel, TProperty>(this HtmlHelper<TModel> htmlHelper, Expression<Func<TModel, TProperty>> expression)
{
var attributes = new RouteValueDictionary {{"class", ""}};
WhenEncountering<StringLengthAttribute>(expression, att => attributes["maxlength"] = att.MaximumLength);
WhenEncountering<HintSizeAttribute>(expression, att =>
{
attributes["class"] += att.Size.ToString().ToLowerInvariant() + " ";
});
attributes["class"] = attributes["class"].ToString().Trim();
return attributes;
}