Html.LabelFor指定的文本 [英] Html.LabelFor Specified Text

查看:145
本文介绍了Html.LabelFor指定的文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都对使用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屋!

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