Dear readers,
After reading and reading I still can't figure out what to do.
For simplicity, I will use an example:
I have a Sql invoice table and an invoiceItems table.
With the great work of the MVC and EF teams, custom scaffolding, etc I can create the basics in no time.
In my Invoice/Edit page I can create an table using a for (int I) loop with Inputs (asp-for=Model.Items[I].Price) again, in no time!
posting this to my controller will update as well the invoice fields, as all the invoice items fields.
The part what I can't figure out is; how I add an extra invoiceItem in the DOM.
A few options so far:
- I could post to an action, create and save an Invoice Item, reload the page.
- move the entire items Table in an partial, ajax this in my page, use option 1. to add and reload the table only (bit nicer...).
- copy the last TR using jquery (won't work, because the naming of the input's will be wrong), als a bit of a problem if the invoice doesn't have items yet :)
- in the past I made an quick and dirty fix; render partial for each row, add 'count' view data, in jquery count the tr's. call partial with count to generate the new TR, problem is that I have to specify all my inputs like this: Name = $"InvoiceItems_[{COUNT}].someField" wich doenst seem like the preferred way :)
at this moment I am using MVC / EF Core, but also looked for answers with comparable techniques.
I will thank you with many many imaginary beers if you could help me towards the normal way to tackle this :)