Note that there are some explanatory texts on larger screens.

plurals
  1. POMVC - Ajax post the contents inside all div tags that exists inside the view?
    primarykey
    data
    text
    <p>I am using MVC3 in my project.</p> <p>I have a view with around 2-12 div tags it depends on how many questions there is, if there is 5 questions there is 5 div tags that looks like an answer form. all these div tags are inside one form.</p> <p>Each div tag have a hiddenfield, textarea and a DropDownList. values inside those fields are used by ajax post that takes the values inside the fields and posts it to my controller.</p> <p>So far I am able to post the first div tag with my code, but the rest of the div tags aint getting posted. What I am looking for is to be able to post all the div tags one by one when "save all" button is clicked. Also all the div tags have the same class name: "wizard-step2". They all also have a ID which is unique and the value of the ID is the QuestionID taken from the database.</p> <p>Here is my jquery code for the post:</p> <pre><code>$("saveall").click(function() { $('#loading2').show(); setTimeout(function () { $("#loading2").hide(); }, 400); var $step = $(".wizard-step2"); // show all steps var Comment = $step.find(".Comment").val(); var QuestionID = $step.find(".QuestionID").val(); var Grade = $step.find(".Grade").val(); var data = { Comment: Comment, QuestionID: QuestionID, Grade: Grade }; $.post('@Url.Action("AnswerForm", "AnswerNKI")', data, function () { }); }); </code></pre> <p>The following code will only save the first div tag but not the rest.</p> <p>this is my HTML:</p> <pre><code>@{ int nr = 1; foreach (SelectedQuestionViewModel items in Model.AllSelectedQuestions) { &lt;div class="wizard-step2" id="@items.QuestionID"&gt; &lt;br/&gt; &lt;br/&gt; &lt;p&gt;@(nr++).&amp;nbsp;@items.SelectedQuestionText &lt;span class="b"&gt;Betyg:&amp;nbsp;&amp;nbsp; @{ var selectListItems = (new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }).Select(i =&gt; new SelectListItem { Text = i.ToString(), Value = i.ToString(), Selected = (items.Grade.HasValue &amp;&amp; i == items.Grade.Value) }); @Html.DropDownList("selectetListItems", selectListItems, "n/a", new { @class = "Grade" }) }&lt;/span&gt;&lt;/p&gt; &lt;div class="editor-field"&gt; @Html.TextArea("Comment", items.Comment, new { @id = "selectstyle3", @class = "Comment" }) &lt;/div&gt; &lt;br/&gt; &lt;br/&gt; @Html.Hidden("QuestionID", items.QuestionID, new { @id = "SelectedQuestions", @class = "QuestionID" }) &lt;br/&gt; &lt;/div&gt; } } </code></pre> <p>Any help is appreciated.</p> <p>Thanks in advance!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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