簡體   English   中英

在子視圖模型中引用DisplayNameFor

[英]Referencing the DisplayNameFor in a child View Model

我有一個視圖模型:

 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

請注意, ObList (大寫O)是一個嵌套類。 但是, DisplayNameFor希望使用某種類型的現有實例的成員。 您可能要解決的成員是obList ,所以這是如何調用其Include屬性的方法:

@Html.DisplayNameFor(model => model.obList[0].Include)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM