【发布时间】:2020-03-22 05:07:04
【问题描述】:
我正在尝试使用数据注释在我的模型类中分配一个显示名称,但视图没有显示该名称。它默认为属性名称并忽略数据注释。
在我的模型中:
public interface IFeedbackLogMetadata
{
[Display(Name="Description")]
string FeedbackDescription { get; set; }
}
public partial class FeedbackLog : PersistantEntity, IFeedbackLogMetadata
{
//..other stuff
}
我也试过了:
[DisplayName("Description")]
string FeedbackDescription { get; set; }
在我看来,我已经尝试过:
@Html.LabelFor(model => model.FeedbackDescription, htmlAttributes: new {@class = "control-label col-md-2"})
<label class="control-label col-md-2">@Html.DisplayNameFor(d => d.FeedbackDescription)</label>
标签显示“FeedbackDescription”。它应该是“描述”。为什么显示名称数据注释被忽略?
【问题讨论】:
-
确保没有
Views/Shared/DisplayTemplates用于覆盖它的字符串。 -
@SteveGreene - 我不知道。
标签: asp.net-mvc razor data-annotations