Это не в моей голове, но это должно помочь вам начать:
public static MvcHtmlString IsRequiredTextBoxFor<TModel, TProperty>(this HtmlHelper<TModel> helper, Expression<Func<TModel, TProperty>> expression)
{
if (expression.IsRequired())
return MvcHtmlString.Create(string.Format("{0} [REQUIRED]", helper.TextBoxFor(expression)));
return helper.TextBoxFor(expression);
}
public static bool IsRequired<T, V>(this Expression<Func<T, V>> expression)
{
var memberExpression = expression.Body as MemberExpression;
if (memberExpression == null)
throw new InvalidOperationException("Expression must be a member expression");
return memberExpression.Member.GetAttribute<RequiredAttribute>() != null;
}
public static T GetAttribute<T>(this ICustomAttributeProvider provider) where T : Attribute
{
var attributes = provider.GetCustomAttributes(typeof(T), true);
return attributes.Length > 0 ? attributes[0] as T : null;
}