Html helper to display display name attribute without label

I have it:

[Display(Name = "Empresa")] public string Company{ get; set; } 

In my aspx, I:

 <th><%: Html.LabelFor(model => model.Company)%></th> 

And this generates:

 <th><label for="Company">Empresa</label></th> 

Are there any helper html extensions to show a display attribute without a label, just plain text? My desired result:

 <th>Empresa</th> 

Thanks!

EDIT

I tried DisplayFor or DisplayTextFor, as suggested, but they are not valid as they generate:

 <th>Amazon</th> 

They return the value of the property ... I want the name from the Display attribute.

+4
source share
1 answer

Late editing

In β†’ MVC4 just use @Html.DisplayNameFor

Before

use your own helper

 public static MvcHtmlString SimpleLabelFor<TModel, TValue>( this HtmlHelper<TModel> html, Expression<Func<TModel, TValue>> expression ) { var metadata = ModelMetadata.FromLambdaExpression(expression, html.ViewData); string htmlFieldName = ExpressionHelper.GetExpressionText(expression); string resolvedLabelText = metadata.DisplayName ?? metadata.PropertyName ?? htmlFieldName.Split('.').Last(); if (String.IsNullOrEmpty(resolvedLabelText)) return MvcHtmlString.Empty; return MvcHtmlString.Create(resolvedLabelText); } 
+12
source

All Articles