I am very new to MVC and need help how I should go about to create an application with the following features.
What I want to do
I have a form that asks some questions to users, and for each question users must be able to add as many items as they want as their answers.
For example, say the application is a recipe book management (Not my actual project), and a user enters the following information:
- Recipe Name (e.g. "Orange Lemonade")
- Description (e.g. "The best lemonade...")
- Fruit Ingredients
- Select fruit from an existing list or type fruit (e.g. lemon)
- Enter quantity (e.g. 3)
NOTE: There are many other ingredients or lists such as Vegetable Ingredient
list, etc, and they have to be entered the same way as Fruit Ingredient
The picture below simply describes the idea...
Here's the code I used: JSFIDDLE (I referred to this site)
My Question
How should I go about to store the list of ingredients like Fruit
, Vegetable
, and the actual application would have many more lists in one form.
Is there a way to call my repository methods to add/delete a list item every time an item is added/deleted?
Or should I save each list to an array and store them when the "Save" button for the form was clicked?
Edit
My question probably wasn't clear but I would like to know if there is a standard way or recommended way to achieve this. If there's none and whichever the method is fine, then I would like to call the repository every time user makes a change to the list. (Users must be able to save the recipe and come back to edit it until they submit the final version of the recipe.) And I'd like to know is how to call the method to save list items to DB from the client side in MVC (not using web controls like ScriptManager
).