我想知道是否有人可以帮助我。我有一个购物篮,其中可以容纳产品,而每个产品可以容纳客户,例如:
购物篮中包含“购买者”(名字,姓氏等)的详细信息,以及 产品详细信息(产品名称,日期等)以及每个产品都有 代表(实际参加活动的人。...名字,姓氏等。
我要创建的表单是一种显示所有产品的表格,在其下方的字段列表中允许购买者输入/修改参加活动的人员的姓名:
我正在努力的是为与会者创建输入字段。我可以使用:
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; }
}
答案 0 :(得分:0)
对不起,哥们,是我.....对象是集合而不是列表,所以我永远无法使用索引来遍历它们。现在排序。谢谢您的时间:)