【发布时间】:2015-12-03 21:15:56
【问题描述】:
我有一个小问题,不知道如何解决。
当我在视图和控制器中写入时:
@Html.DisplayFor(modelItem => item.Category.Name)
return View(db.Product.Include(p=>p.Category).OrderByDescending(a => a.ProductID).Where(c => c.ClientID == clientid).ToList());
当我将其更改为:
@Html.DisplayFor(modelItem => item.CategoryID)
return View(db.Product.OrderByDescending(a => a.ProductID).Where(c => c.ClientID == clientid).ToList());
所以一切正常,但它不显示类别名称。我该如何解决?
编辑1:
public partial class Product
{
public int ID { get; set; }
public int ProductID { get; set; }
public string Name { get; set; }
public int CategoryID { get; set; }
public decimal Price { get; set; }
public int Promotion { get; set; }
public string Image1 { get; set; }
public string Image2 { get; set; }
public string Image3 { get; set; }
public string Image4 { get; set; }
public string Description { get; set; }
public int ClientID { get; set; }
public virtual Category Category { get; set; }
public virtual Client Client { get; set; }
}
【问题讨论】:
标签: c# asp.net asp.net-mvc view controller