Html.LabelFor Specified Text

后端 未结 7 1583
渐次进展
渐次进展 2020-12-24 04:28

Anyone got any idea on how to specify text when using Html.LabelFor(c=>c.MyField). It\'s just MyField might not be an appropriate name to displ

7条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-24 05:08

    You use System.ComponentModel.DataAnnotations.DisplayAttribute:

    [Display(Name = "My Field")]
    public string MyField { get; set; }
    

    Setting the ResourceType property on your attribute will allow you to use a resource file.

    (Prior to .NET 4 use System.ComponentModel.DisplayNameAttribute with the caveat that the display name must be a compile-time constant.)

提交回复
热议问题