我正在尝试使用数据注释在模型类中分配显示名称,但是视图未显示该名称。默认为属性名称,并忽略数据注释。
在我的模型中:
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”。它应该是“描述”。为什么显示名称数据注释会被忽略?
答案 0 :(得分:0)
/ 头疼 /
我需要用MetadataType为接口装饰部分类。没有这个,视图就从EF生成的类中拉出,该类没有数据注释。
[MetadataType(typeof(IFeedbackLogMetadata))]
public partial class FeedbackLog : PersistantEntity, IFeedbackLogMetadata
{
//...other stuff
}