Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I bind a DropDownList to an Ajax form with both post and get support?
    text
    copied!<p>I have a registration form for registering personal attributes. I am using both included <code>Ajax.BeginForm</code> function and also JSON to serialize the form. This form is updating the attributes and also showing the attributes if available in DB. So if a user enter the values and click the save button it is serializing the form and saving it into the db. When a user call the page; it is also using JSON to fill the form from DB if there is a available record if not just showing a blank form as usual.</p> <p>Please find a part of the View below.</p> <pre><code>@using (Ajax.BeginForm( "savepeople", "people", FormMethod.Post, new AjaxOptions { OnComplete = "savePicture" }, new { id = "frPeople" })) { @Html.ValidationSummary(true, "Problem during saving...") &lt;fr&gt; &lt;h2&gt; Personal Details&lt;/h2&gt; &lt;br /&gt; &lt;legend&gt;Person&lt;/legend&gt; &lt;div class="editor-label"&gt; @Html.LabelFor(model =&gt; model.People.Title) &lt;/div&gt; &lt;div class="editor-field"&gt; @Html.EditorFor(model =&gt; model.People.Title) @Html.ValidationMessageFor(model =&gt; model.People.Title) &lt;/div&gt; &lt;div class="editor-label"&gt; @Html.LabelFor(model =&gt; model.People.Description) &lt;/div&gt; &lt;div class="editor-field"&gt; @Html.EditorFor(model =&gt; model.People.Description) @Html.ValidationMessageFor(model =&gt; model.People.Description) &lt;/div&gt; &lt;p&gt; &lt;input id="saveMarker" type="submit" value="Save" /&gt; &lt;/p&gt; } </code></pre> <p>So I am using a model like:</p> <pre><code>namespace MyProject.Models { public class Profile { public People People { get; set; } // I am also referencing other models here... } public partial class People { public int PeopleId { get; set; } public Guid UserId { get; set; } public string Title { get; set; } public string Description { get; set; } // It has other attributes also... } </code></pre> <p>And controller has the classic post and get functions compatible with JSON to call and update the page.</p> <p><strong>My problem is: I am already able to handle these operations with <code>TextBox</code>'s but I want to add a predefined <code>DropDownList</code> to use it for both saving/updating and also showing the values if it has a saved record in db.</strong></p> <p>Do you have any idea about how tho handle this issue?</p>
 

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