Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to Init start values in DropDown using Jquery
    primarykey
    data
    text
    <p> Six Five Three One </p> <p>And I have controller:</p> <pre><code> DBEntity context = new DBEntity(); // My EntityModel public ActionResult Index() { return View(); } public JsonResult GetStartValues() { var b = context.MyTable.ToList(); return Json(ConvertObj(b)); } private object ConvertObj(List&lt;MyTable&gt; lst) { var list = new object[lst.Count]; for (int i = 0; i &lt; lst.Count; i++) { list[i] = new { value = lst[i].MyValue, name = lst_meals[i].MyText }; } return list; } </code></pre> <p>My question is: How to Init this values as start values <strong>using jQuery</strong>. I can use solution like this:</p> <pre><code> public ActionResult Index() { var model = context.MyTable.ToList() return View(model); } </code></pre> <p>In .aspx </p> <pre><code> &lt;select id="myDropdown" name="myDropdown"&gt; &lt;% foreach(var obj in Model.MyTableList) {%&gt; &lt;option value="&lt;%: obj.MyValue %&gt;"&gt;&lt;%: obj.MyText %&gt;&lt;/option&gt; &lt;% } %&gt; </code></pre> <p>But I want use Jquery for this)</p> <p>I want to populate the drop down list by making an asynchronous call to a service, but I don't know what event I have to use... If I trying to populate drop down:</p> <pre><code> $(document).ready(function () { $.post("/GetStartValues/", { }, function (data) { populateDropdown($("#[id*='myDropdown']"), data); }); } function populateDropdown(select, data) { select.html(''); //clear all items $.each(data, function (id, option) { select.append($('&lt;option&gt;&lt;/option&gt;').val(option.value).html(option.name)); }); } </code></pre> <p>But it isn't working. I want to insert values into DropDown using Jquery request as soon as page is loaded.</p>
    singulars
    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