asp.net-mvc - MVC 查看列表中包含的列表的显示项
问题描述
我想知道是否有人可以帮助我。我有一个可以包含产品的购物篮,每个产品都可以包含客户,例如:
一个购物篮包含“购买者”的详细信息(名字、姓氏等)和产品详细信息(产品名称、日期等),每个产品都有代表(实际参加活动的人......名字、姓氏、等等
我要创建的是一个表单,它显示所有产品,下面有一个字段列表,允许购买者输入/修改参加活动的人的姓名:
我正在努力为与会者创建输入字段。我可以用:
foreach(var dele in product.delegates)
{
<p>@dele.FirstName</p>
}
它确实按预期显示了与会者的姓名列表,但我希望能够使用以下内容:
for(var i=0, i < product.delegates.Count; i++)
{
@Html.TextBoxFor(x => x[i].FirstName)
}
但这会显示购买者的姓名(重复),而不是与会者。
有人可以帮忙吗?就像我说的,我想显示一个可以修改并发布ActionResult
到更新数据库的输入列表。
作为注释,我可以看到模型填充了我期望的信息。
public class ShoppingCart
{
public int ShoppingCartId { get; set; }
public DateTime Created { get; set; }
public string TransStatus { get; set; }
public bool Completed { get; set; }
public string ContactNumber { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string Phone { get; set; }
public string Mobile { get; set; }
public string CompanyName { get; set; }
public string PostCode { get; set; }
public string Email { get; set; }
public string Address1 { get; set; }
public string Address2 { get; set; }
public string Address3 { get; set; }
public string City { get; set; }
public string County { get; set; }
public string StoreKey { get; set; }
public DateTime? SentToStore { get; set; }
public virtual ICollection<ShoppingCartProduct> Products { get; set; }
}
public class ShoppingCartProduct
{
public int ShoppingCartProductId { get; set; }
public int ShoppingCartId { get; set; }
public string ProductId { get; set; }
public string CourseId { get; set; }
public string ProductName { get; set; }
public string ProductType { get; set; }
public decimal ItemPrice { get; set; }
public string Location { get; set; }
public DateTime? EventDate { get; set; }
public int Quantity { get; set; }
public decimal TotalPrice => ItemPrice * Quantity;
public virtual ShoppingCart ShoppingCart { get; set; }
public virtual ICollection<ShoppingCartDelegate> delegates { get; set; }
}
public class ShoppingCartDelegate
{
public int ShoppingCartDelegateID { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string email { get; set; }
public int ShoppingCartProductId { get; set; }
public virtual ShoppingCartProduct ShoppingCartProduct { get; set; }
}
解决方案
对不起,伙计,是我......对象是集合而不是列表,所以我永远无法用索引遍历它们。现在排序。谢谢你的时间:)
推荐阅读
- javascript - Javascript:从数组中获取连续天数?
- python - 不能对正则表达式的年份值进行操作
- sql-server - 在 Codeigniter 中使用 SQL Server 变量
- scala - Scala:获取列表中最后一个对象的 id 属性,如果列表为空,则获取 None
- reactjs - Material-ui/pickers:隐藏标签
- angular - Angular ngOnDestroy
- windows - Windows 服务可以写入 HKEY_USERS 吗?
- python - 为什么我的 Kivy windows Executable 没有运行?
- python - 正则表达式:以关键字开头的句子以句子空白输出结尾
- php - PHP标头不会重定向回起始页面