在 Razor 引擎中,我使用了 LabelFor
辅助方法来显示名称
但是显示名称似乎不太好显示。 所以我需要更改我的显示名称如何操作....
@Html.LabelFor(model => model.SomekingStatus, new { @class = "control-label"})
最佳答案
您可以使用 [DisplayName]
属性来装饰 View 模型属性并指定要使用的文本:
[DisplayName("foo bar")]
public string SomekingStatus { get; set; }
或者使用 LabelFor 帮助器的另一个重载,它允许您指定文本:
@Html.LabelFor(model => model.SomekingStatus, "foo bar")
而且,不,您不能像您尝试的那样在 MVC3 中指定类名,因为 LabelFor
帮助程序不支持这一点。但是,这在 MVC4 或 5 中可以工作。
关于asp.net-mvc-3 - 如何更改mvc3中razor中LabelFor的显示名称?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11651254/