1

Bellow are my tables

enter image description here

Here I am trying to add Survey & all the questions of it.

right now I am creating survey first , then going to next page to add questions & going to one more page to add options/answers related that questions.

i.e. I have created 3 pages 1. To add survey 2. To add question 3. To add options/answers

Here there will be multiple inserts happening which I want to avoid

Now I want to do all this thing in one page & want to insert all records in single insert, I am using entity framework so I can create add all data in Survey object & then just insert it. But I don't know how I do it in single page using AJAX i.e.

Edit : I used This tutorial For adding records using PartialViews. This works for adding Questions but does not work for adding answers to that questions.

vaibhav shah
  • 4,939
  • 19
  • 58
  • 96
  • You'll need list binding and relationships inside your models. What specifically do you need help with? – beautifulcoder Mar 16 '15 at 20:49
  • If you see this tutorial http://ivanz.com/2011/06/16/editing-variable-length-reorderable-collections-in-asp-net-mvc-part-1/ .. Just like this I able to add Questions for My Survey. But I am not able to add answers to that Question in same page. – vaibhav shah Mar 16 '15 at 20:51
  • 1
    @vaibhavshah, Of course you can, its just a matter of correctly naming your controls. For example the first answer to the first question needs an input with `name="Questions[0].Answers[0].Description"` –  Mar 16 '15 at 21:50
  • @StephenMuecke but I need delete functionality as well. If I do like you said then there will be problem if I remove any answer. – vaibhav shah Mar 21 '15 at 22:43
  • If you want delete functionality, then you need a special input that defines an indexer value as well e.g. ``. This allows you to post back non-consecutive indexers. The answers [here](http://stackoverflow.com/questions/29161481/post-a-form-array-without-successful/29161796#29161796) and [here](http://stackoverflow.com/questions/28019793/submit-same-partial-view-called-multiple-times-data-to-controller/28081308#28081308) might help to explain. –  Mar 21 '15 at 22:50

0 Answers0