I have an HtmlHelper extension method that looks like this:
public static MvcHtmlString TextBoxWithMaxLengthFor<TModel, TProperty>(this HtmlHelper<TModel> html, Expression<Func<TModel, TProperty>> expression, string name)
{
return html.TextBoxFor(expression, new { maxlength = 50 });
}
I’d like to replace the 50 with the value of the StringLength data annotation on the given property, if one is defined. How do I go about getting at the property’s attributes?
Found the answer: