Html.LabelFor指定文本[ASP.NET MVC 2] [英] Html.LabelFor Specified Text [ASP.NET MVC 2]
问题描述
任何人有关于如何使用 Html.LabelFor时指定文本任何想法(C => c.MyField)
。它只是 MyField的
可能不是一个合适的名称在屏幕上显示,您可能希望超级神奇场代替,但不会出现任何过载。
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.
任何想法?
推荐答案
您使用<一个href=\"http://msdn.microsoft.com/en-us/library/system.componentmodel.dataannotations.displayattribute.aspx\"><$c$c>System.ComponentModel.DataAnnotations.DisplayAttribute$c$c>:
[Display(Name = "My Field")]
public string MyField { get; set; }
设置<一个href=\"http://msdn.microsoft.com/en-us/library/system.componentmodel.dataannotations.displayattribute.resourcetype.aspx\"><$c$c>ResourceType$c$c>在你的属性属性将允许您使用的资源文件。
Setting the ResourceType
property on your attribute will allow you to use a resource file.
(在此之前.NET 4使用<一个href=\"http://msdn.microsoft.com/en-us/library/system.componentmodel.displaynameattribute.aspx\"><$c$c>System.ComponentModel.DisplayNameAttribute$c$c>需要提醒的是显示名称必须是一个编译时间常数。)
(Prior to .NET 4 use System.ComponentModel.DisplayNameAttribute
with the caveat that the display name must be a compile-time constant.)
这篇关于Html.LabelFor指定文本[ASP.NET MVC 2]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!