2016-04-22 165 views

回答

1

添加注释在PostQuery模型

class PostQuery 
{ 
[Display(Name="Post Query")] 
public int ProjectId {get; set; } 
... 
} 
+0

亚历山大,是的,这将工作,但会要求每一个属性。我正在寻找重写LabelFor生成器,只显示最后的属性名称,而不是整个链到达那里。 –

1

史蒂芬,

我想你可以通过实现自己的HtmlConventionRegistry

public class DefaultAspNetMvcHtmlConventions : HtmlConventionRegistry 
{ 
    public DefaultAspNetMvcHtmlConventions() 
    { 
     Labels.Always.ModifyWith(er => er.CurrentTag.Text(er.Accessor.Name)); 
    } 
} 

然后申请您的注册表,将其添加到之前覆盖约定你IoC容器(这里是我的结构图)

public class HtmlTagRegistry : Registry 
{ 
    public HtmlTagRegistry() 
    { 
     var htmlConventionLibrary = new HtmlConventionLibrary(); 
     new DefaultHtmlConventions().Apply(htmlConventionLibrary); 
     new DefaultAspNetMvcHtmlConventions().Apply(htmlConventionLibrary); 
     For<HtmlConventionLibrary>().Use(htmlConventionLibrary); 
    } 
}