Html.LabelFor指定的文本 [英] Html.LabelFor Specified Text
问题描述
任何人都对使用Html.LabelFor(c=>c.MyField)
时如何指定文本有任何想法.只是MyField
可能不是在屏幕上显示的合适名称,您可能想要"Super Fantastic Field",但似乎没有任何重载.
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 display on screen, you may want "The Super Fantastic Field" instead, but there doesn't appear to be any overloads.
有什么想法吗?
推荐答案
您使用 System.ComponentModel.DataAnnotations.DisplayAttribute
:
[Display(Name = "My Field")]
public string MyField { get; set; }
设置 ResourceType
属性上的属性将允许您使用资源文件.
Setting the ResourceType
property on your attribute will allow you to use a resource file.
(在.NET 4之前,请使用 System.ComponentModel.DisplayNameAttribute
请注意,显示名称必须是编译时常量.)
(Prior to .NET 4 use System.ComponentModel.DisplayNameAttribute
with the caveat that the display name must be a compile-time constant.)
这篇关于Html.LabelFor指定的文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!