0

我有一个视图模型:

 public class ObjectiveVM
 {
    public DateTime DatePeriod { get; set; }
    public IList<ObList> obList { get; set; }
    public class ObList
    {
        public int ObjectiveId { get; set; }
        public int AnalystId { get; set; }
        public string Title { get; set; }
        public string Description { get; set; }
        public string AnalystName { get; set; }
        public bool Include { get; set; }
    }
 }

视图模型填充在控制器中,并具有我需要的信息: ss

在我看来,如何访问表头的 DisplayName:

    @model IEnumerable<Objectives.ViewModels.ObjectiveVM>
    ...
    ...
    <th>
        @Html.DisplayNameFor(model => model.ObList.Include)
    </th>

在上面尝试时,我收到错误:

'ObList': cannot reference a type through an expression; try 'Objectives.ViewModels.ObjectiveVM.ObList' instead

我也试过:

@model Objectives.ViewModels.ObjectiveVM

...但再次收到错误:

 'ObList': cannot reference a type through an expression; try 'Objectives.ViewModels.ObjectiveVM.ObList' instead
4

1 回答 1

1

请注意,ObList(大写 O)是一个嵌套类。DisplayNameFor然而,期望某种类型的现有实例的某些成员可以使用。您可能试图解决的成员是obList,所以这里是如何调用它的Include属性:

@Html.DisplayNameFor(model => model.obList[0].Include)
于 2013-08-15T07:57:08.303 回答