正解だと理解した場合は、ビューモデルに属性のリストがあります。
したがって、それを操作したい場合は、リストに配置する必要があります。
したがって、ビューモデルを変更する必要があります:
//I put all properties of your list to separate model
public class AttriduteViewModel
{
public int ProductColorVariantId { get; set; }
public int ProductSizeVariantId { get; set; }
public int ProductSizeVariantValueId { get; set; }
public int ProductAttributeId { get; set; }
public int ProductAttributeValueId { get; set; }
public int? Quantity { get; set; }
}
public class ProductAttributesViewModel
{
public Product Product { get; set; }
public ProductAttribute ProductAttribute { get; set; }
public ProductAttributeValue ProductAttributeValue { get; set; }
public int ProductId { get; set; }
public string Name { get; set; }
[AllowHtml]
public string Description { get; set; }
public decimal? Price { get; set; }
public string Sizes { get; set; }
public int Stock { get; set; }
//note this line
public List<AttriduteViewModel> AdditionalAttridutes {get; set;}
}
基本的にはこれですべてです。ここで、AdditionalAttridutesに対してのみ正しいバインディングを作成する必要があります 。 HtmlHelpersを使用すると簡単に作成できます Html.DropDownListForのように 、Html.HiddenFor およびHtml.TextBoxFor 。ビューに表示されません。
inputを作成する場合が重要です ■ヘルパーを使用すると、正しいnameが得られます 属性とモデルはPOSTで正しくバインドされます 。
あなたが直面するもう一つのことは、あなたの例のように動的に新しいアイテムを作成することです。正しい名前の属性について考える必要があります。 このすばらしい回答 を確認することをお勧めします その問題について。