I know this is old, but I faced this problem recently with an ASP.NET MVC3 project and implemented a solution.
1. Create a custom attribute to store the help text
public class HelpTextAttribute : DescriptionAttribute
{
public HelpTextAttribute(string helpText)
: base(helpText)
{ }
}
2. Create a HtmlHelper extension method to retrieve the attribute value
public static class HtmlHelperExtensions
{
public static string HelpTextFor<TModel, TValue>(this HtmlHelper<TModel> html, Expression<Func<TModel, TValue>> expression)
{
var memberExpression = expression.Body as MemberExpression;
if (memberExpression == null)
throw new InvalidOperationException("Expression must be a member expression");
var attributes = memberExpression.Member.GetCustomAttributes(typeof(HelpTextAttribute), true);
var attribute = attributes.Length > 0 ? attributes[0] as HelpTextAttribute : null;
return html.Encode(attribute == null ? string.Empty : attribute.Description);
}
}
3. Annotate the model property with the HelpText attribute
[HelpText("A level from which to start")]
[Required("You must select a level")]
public int Level { get; set; }
4. Simply use the new HtmlHelper extension method with your view
<div class="editor-help">
<%: Html.HelpTextFor(model => model.Level) %>
</div>