Note that there are some explanatory texts on larger screens.

plurals
  1. POSaving answers to questioniare (content) via ajax call on a mvc 3 page?
    text
    copied!<p>I have a list of questions and I want to save user answers via an ajax call. For example I have 50 questions not sure if I need to loop thru all 50 question and send each answer to a controller (save) or its possible to send results as large data to a controller. </p> <p>my view:</p> <pre><code>@using COPSGMIS; @model IEnumerable&lt;COPSGMIS.Models.Quiz&gt; @{ ViewBag.Title = "Questionaire"; } &lt;h2&gt;Questionaire&lt;/h2&gt; &lt;input type="hidden" id="currentstep" name="currentstep" /&gt; @using (Html.BeginForm("Questionaire", "Question", FormMethod.Post, new { id = "SignupForm" })) { &lt;div id="wizardtemplate"&gt; @foreach (var step in Model) { &lt;fieldset class="wizard"&gt; &lt;div class="page_Title"&gt; @Html.DisplayFor(modelItem =&gt; step.Title)&lt;/div&gt; @foreach (var question in step.Results) { ... code removed .... &lt;label for="question"&gt;@Html.DisplayFor(modelItem =&gt; question.NumberedQuestion)&lt;/label&gt; @Html.Raw(Html.DisplayControl(question.QuestionID, question.Choices, question.AnswerValue,question.ControlType)) &lt;/div&gt; @Html.Partial("_Comment", question) &lt;hr /&gt; } &lt;/fieldset&gt; } </code></pre> <p>HTML rendered:</p> <pre><code>&lt;label for="question"&gt;3. This is a sample question (2) for the questionare?&lt;/label&gt; &lt;div class='answer'&gt;&lt;input type='date' id='3' name='3' value='2012-12-10' /&gt;&lt;/div&gt; &lt;/div&gt; ... code removed .... &lt;label for="question"&gt;4. This is a sample question (3) for the questionare?&lt;/label&gt; &lt;div class='answer'&gt;&lt;input type='text' id='4' name='4' value='999' /&gt;&lt;/div&gt; &lt;/div&gt; </code></pre> <p>Model:</p> <pre><code> public class Quiz { public int ReviewID { get; set; } public int StepID { get; set; } public string Title { get; set; } public virtual IEnumerable&lt;Result&gt; Results { get; set; } } </code></pre> <p>ajax call:</p> <pre><code>function SaveAnswer(//not sure what needs to be passed) { $.ajax({ url: '/Question/SaveQuestionaire', type: 'POST', cache: false, dataType: 'json', data: ({ // not sure what this will look like? }), error: function (jqXHR, textStatus, errorThrown) { alert(errorThrown); }, success: function (json) { // Message to confirm save } }); } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload