我有一个视图模型 InvoiceViewModel ,并且在 InvoiceViewModel 中,我有一个属性Items,它是类型列表
public class InvoiceViewModel
{
[Key]
public int InvoiceNumber { get; set; }
public int ClientID { get; set; }
public List<ItemsViewModel> Items { get; set; }
...
}
ItemsViewModel 模型如下所示
public class ItemsViewModel
{
public string Name { get; set; }
public string UnitPrice { get; set; }
public string Quantity { get; set; }
public string TotalAmount { get; set; }
}
以下字段是使用jQuery动态添加到HTML中的
<tr id="InvoiceLine-606818967">
<td class="text-left line-description">
<textarea name="Items[].Name" id="line-description-606818967" class="band autogrow" rows="1"></textarea>
</td>
<td class="text-right line-unit-cost">
<input type="number" name="Items[].UnitPrice" placeholder="0.00" min="0.00" step="0.01">
</td>
<td class="text-right line-quantity">
<input type="number" name="Items[].Quantity" placeholder="0">
</td>
</tr>
<tr id="InvoiceLine-2196849859">
<td class="text-left line-description">
<textarea name="Items[].Name" id="line-description-2196849859" class="band autogrow" rows="1"></textarea>
</td>
<td class="text-right line-unit-cost">
<input type="number" name="Items[].UnitPrice" placeholder="0.00" min="0.00" step="0.01">
</td>
<td class="text-right line-quantity">
<input type="number" name="Items[].Quantity" placeholder="0">
</td>
</tr>
<tr id="InvoiceLine-7114958211">
<td class="text-left line-description">
<textarea name="Items[].Name" id="line-description-7114958211" class="band autogrow" rows="1"></textarea>
</td>
<td class="text-right line-unit-cost">
<input type="number" name="Items[].UnitPrice" placeholder="0.00" min="0.00" step="0.01">
</td>
<td class="text-right line-quantity">
<input type="number" name="Items[].Quantity" placeholder="0">
</td>
</tr>
提交表单后,在调试 InvoiceViewModel
时会看到以下内容请告知我我做错了什么事
答案 0 :(得分:3)
我不知道您的错误消息,但是也许您可以编写Items[iterationIndex].Quantity
或item.Quantity
等。可能在提交表单时,模型不知道哪个索引是我的