views:

103

answers:

1

Not really sure if the title reflects what I am actually trying to achieve...

I have a view which is used to create a record (invoice) on the same page I would like to be able to add rows to the invoice dynamically or how ever this is achieved. I am just not sure how to do this with MVC and hope someone can point me in the right direction.

Cheers, Daniel

A: 

I'd do that with AJAX. The lifecycle would be:

  1. Show the Invoice form for its creation: you can not add rows to it yet, because it is not saved and therefore it has no persistent object attached to it yet
  2. Save the invoice: reload the form. Now you can start adding rows
  3. When you add a row, you invoke the InvoiceItem/Create action via Javascript passing it the invoice ID and all the remaining data that need to be filled
  4. When the AJAX action returns, you reload the part of the page that renders the Invoice Items (by calling InvoiceItem/Index/ action and rendering its results), so you reflect the recent changes

To create or edit the item, you could use a javascript popup like lightbox, which will make the page look cleaner.

I implemented this for attachments, and works great, and is very clean.

Palantir