【发布时间】:2014-05-19 15:52:31
【问题描述】:
我正在用 ASP MVC 4 做一个 Web 项目。
我有一个强类型(model :Product) 视图 (ProductIndex.cshtml),我想在此视图中显示所有商家的列表。
最好的方法是什么?
- 在我的产品类 (Icollection) 中创建一个新属性?
我不太喜欢这种方法,因为产品不应该有商家列表...
- 创建一个部分视图类型(IEnumerable)并从我的 ProductIndex 视图中调用它,并使用 ViewData 对象作为参数?
我不确定我是否能够使用这种方法在列表框中显示模型(IEnumerable)...我想我只能使用属性而不是模型填充列表框...
请告诉我!
谢谢
public class Product
{
public int ProductID { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public int MerchandID { get; set; }
}
public class ProductViewModel
{
public int ProductID { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public int MerchandID { get; set; }
public ICollection<Merchant> Lesmarchands { get; set; }
}
【问题讨论】:
标签: html asp.net-mvc razor view listbox