There is no such assistant out of the box.
But trivially easy to write custom:
public static class HtmlExtensions { public static string DisplayNameFor<TModel, TProperty>( this HtmlHelper<TModel> html, Expression<Func<TModel, TProperty>> expression ) { var htmlFieldName = ExpressionHelper.GetExpressionText(expression); var metadata = ModelMetadata.FromLambdaExpression(expression, html.ViewData); return (metadata.DisplayName ?? (metadata.PropertyName ?? htmlFieldName.Split(new[] { '.' }).Last())); } }
and then use it (after creating the namespace in which you defined it in scope):
@Html.ActionLink( "Customer Number", "Search", new { Search = ViewBag.Search, q = ViewBag.q, sortOrder = ViewBag.CustomerNoSortParm, customerNumberDescription = Html.DisplayNameFor(model => model.CustomerNumber) } )
source share