没有这种开箱即用的助手。
但是编写一个自定义的非常容易:
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()));
}
}
然后使用它(在将定义它的命名空间带入范围之后):
@Html.ActionLink(
"Customer Number",
"Search",
new {
Search = ViewBag.Search,
q = ViewBag.q,
sortOrder = ViewBag.CustomerNoSortParm,
customerNumberDescription = Html.DisplayNameFor(model => model.CustomerNumber)
}
)