I have a view model InvoiceViewModel and inside the InvoiceViewModel I have a property Items which is type list.
public class InvoiceViewModel
{
[Key]
public int InvoiceNumber { get; set; }
public int ClientID { get; set; }
public List<ItemsViewModel> Items { get; set; }
...
}
The ItemsViewModel model looks like this
public class ItemsViewModel
{
public string Name { get; set; }
public string UnitPrice { get; set; }
public string Quantity { get; set; }
public string TotalAmount { get; set; }
}
The following fields get added into the HTML using jQuery dynamically
<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>
When the form is submitted, the following is what I see during debugging of the InvoiceViewModel
Please advise what am I doing wrong?