javascript - How to save list items to DB in MVC when add/delete list items is managed on the same page -


i new mvc , need how should go create application following features.

what want do

i have form asks questions users, , each question users must able add many items want answers.

for example, application recipe book management (not actual project), , user enters following information:

  • recipe name (e.g. "orange lemonade")
  • description (e.g. "the best lemonade...")
  • fruit ingredients
    • select fruit existing list or type fruit (e.g. lemon)
    • enter quantity (e.g. 3)

note: there many other ingredients or lists such vegetable ingredient list, etc, , have entered same way fruit ingredient

the picture below describes idea...

enter image description here

here's code used: jsfiddle (i referred this site)

my question

how should go store list of ingredients fruit, vegetable, , actual application have many more lists in 1 form.

is there way call repository methods add/delete list item every time item added/deleted?

or should save each list array , store them when "save" button form clicked?

edit

my question wasn't clear know if there standard way or recommended way achieve this. if there's none , whichever method fine, call repository every time user makes change list. (users must able save recipe , come edit until submit final version of recipe.) , i'd know how call method save list items db client side in mvc (not using web controls scriptmanager).

this question hard answer because depends on application. way implement based on how application used , expectations both , user.

consider following questions:

  1. do have finish entire recipe before saving , having persisted?
  2. are willing live incomplete recipes?
  3. do expect take days complete task , allow user save , continue later?
  4. is there draft, in progress, complete, published type status task progress thru?

based on answers these questions think able answer own question. answers elucidate requirements , way go far architecture.