I have built a extention for the LabelFor that looks like this :
public static MvcHtmlString LabelFor<TModel, TValue>(this HtmlHelper<TModel> self, Expression<Func<TModel, TValue>> expression, Boolean showToolTip, string sufix = "")
{
string description = string.Empty;
var metadata = ModelMetadata.FromLambdaExpression(expression, self.ViewData);
if (showToolTip)
description = metadata.Description;
return LabelFor(metadata.DisplayName, description, self.ViewContext.ViewData.TemplateInfo.GetFullHtmlFieldId(ExpressionHelper.GetExpressionText(expression)), sufix: sufix);
}
This is used like this :
<%: Html.LabelFor(model => model.ModelViewAd.TypeOfAd, false)%>
The Property do have the Display attribute like this :
[Display(Name = "Type of ad", Description = "")]
With a breakpoint I can see that the metadata.DisplayName is set to null?
The problem when away without any changes after a couple of cleans and rebuilds. So the code is correct.