views:

36

answers:

1

Hi,

I have a Question table and an Answers table linked by questionID (1 to many). I'd like to be able to update both table from the one form.

I can easily add a question but to have it also add the answers (into their own recordsets) is causing a headache.

how do I set my form up to allow for the answers to be created and also what do I do in the Controller.

Any help would be gratefully appreciated as I've not been able to locate any good examples on the web.

thanks in advance.

A: 

Do you want to be able to submit multiple answers at one time or have a text box under the question which allows one answer per submit? It sounds like the former and perhaps this is for populating some data out of the typical work flow that would happen where one person would come along and give one answer (like this site)?

You could have your Controller method look like this:

public ActionResult AddQuestionWithAnswers(Question question, List<Answer> answers)

Then create a class for Question and one for Answer and read Haack's blog post on submitting lists -- in the second example, the products are answers for your scenario.

On the frontend, use JavaScript to add an empty answer box at the end of the answers each time the user starts filling in the last box. With the array method above, you can add as many boxes as you wish keeping them all in one form.

Cymen
Thanks for that. Yeah the back-end should be able to submit multiple answer options for the question (which is where I'm having the problem) as the front-end they can only select one answer (this side of it is working).
mailman1979
Ah! There was some confusion -- do you want the user to be able to submit a question with multiple-choice answers and the user selects which of the multiple choice answers are correct? Or are these multiple written answers the user is submitting?
Cymen