您如何访问DisplayNameFor
嵌套模型中的 - 即:
public class Invoice
{
public int InvoiceId { get; set; }
public string CustomerName { get; set; }
public string Contact { get; set; }
public IList<InvoiceItem> InvoiceItems { get; set; }
}
public class InvoiceItem
{
public int InvoiceItemId { get; set; }
public int InvoiceId { get; set; }
[Display(Name = "Item Heading")]
public string Item { get; set; }
[Display(Name = "Item Description")]
public string Description { get; set; }
public virtual Invoice Invoice { get; set; }
}
我可以按如下方式遍历嵌套项:
@foreach (var item in Model.InvoiceItems)
{
@Html.DisplayFor(modelItem => item.Item)
<br />
@Html.DisplayFor(modelItem => item.Description)
<br />
}
但我怎么去:[Display(Name = "Item Heading")]
@Html.DisplayNameFor(modelItem => modelItem.Item)
我得到错误:'inv5.Models.Invoice' does not contain a definition for 'Item' and no extension method 'Item' accepting a first argument of type 'inv5.Models.Invoice' could be found
谢谢,马克