I see the DisplayAttribute
has a ShortName
property, but I see no Html.ShortName
helper. How can I get to use this short name for my table column headings? Do I have to write my own helper?
You could write your own helper :
Something like
public static IHtmlString ShortLabelFor<TModel, TValue>(this HtmlHelper<TModel> helper, Expression<Func<TModel, TValue>> expression) {
var metadata = ModelMetadata.FromLambdaExpression(expression, helper.ViewData);
var content = metadata.ShortDisplayName?? metadata.DisplayName ?? /*something else*/ ?? string.Empty;
return new HtmlString(content);
}
But, from msdn :
The short display name can be used in a tooltip or in other display contexts such as the title of tabular list views where the complete display name might not fit. For example, in MVC, this name is used in tables where the columns are not wide enough to display the complete field name. If this field is null, DisplayName should be used.
So it looks like it should be automatic (when no room enough), but... untested here. Sounds like it should work with @Html.LabelFor in this way.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With