Html.LabelFor指定文本[ASP.NET MVC 2] [英] Html.LabelFor Specified Text [ASP.NET MVC 2]

查看:327
本文介绍了Html.LabelFor指定文本[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:

[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在你的属性属性将允许您使用的资源文件。

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需要提醒的是显示名称必须是一个编译时间常数。)

(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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆