DisplayName无效

时间:2011-12-01 09:13:21

标签: asp.net-mvc attributes grid

模型:

[Display(Name = "Status")]
public bool IsApproved { get; set; }

在视图中:

@Html.Grid(Model.Users).Sort(Model.GridSortOptions).Columns(column =>
{
    column.For(ulv => ulv.Name);
    column.For(ulv => ulv.SurName);
    column.For(ulv => ulv.IsApproved.Equals(true) ? "Approved" : "Not Approved").Sortable(false);

})

Dismplay name“status” - 未显示。列名为空

1 个答案:

答案 0 :(得分:1)

因为您没有在column.For属性上执行IsApproved,而是在字符串"Approved""Not Approved"上执行此操作。

您需要将其他属性添加到视图模型并进行装饰:

public bool IsApproved { get; set; }

[Display(Name = "Status")]
public string IsApprovedString
{
    get { return this.IsApproved ? "Approved" : "Not Approved"; }
}