Note that there are some explanatory texts on larger screens.

plurals
  1. POUpdating Html.Dropdownlists using JQuery
    primarykey
    data
    text
    <p>I found this solution on here <a href="https://stackoverflow.com/questions/2782815/how-to-update-strongly-typed-html-dropdownlist-using-jquery">How to update strongly typed Html.DropDownList using Jquery</a> and am trying to implement it, but something is bugged in it.</p> <pre><code>$(function() { $('#cid').change(function() { var selectedCompany = $(this).val(); var ddl = $("#foid"); $.post("/TimeTracking/FilterFieldOffices", { companyId: selectedCompany }, function (data) { $(ddl).loadSelect(data); }); }); }); (function($) { $.fn.emptySelect = function() { return this.each(function() { if (this.tagName == 'SELECT') this.options.length = 0; }); } $.fn.loadSelect = function(optionsDataArray) { return this.emptySelect().each(function() { if (this.tagName == 'SELECT') { var selectElement = this; $.each(optionsDataArray, function(index, optionData) { var option = new Option(optionData.Text, optionData.Value); if ($.browser.msie) { selectElement.add(option); } else { selectElement.add(option, null); } }); } }); } })(jQuery); </code></pre> <p>My controller returns a select list of what i want.</p> <pre><code>public ActionResult FilterFieldOffices(int companyId = 0) { IList&lt;FieldOffice&gt; list = _fodp.GetFieldOfficesForCompany(companyId); var returnList = new SelectList(list, "Id", "FacilityName"); return Json(returnList); } </code></pre> <p>I know the .change function is firing by placing alerts, and i know that my controller function is being called through breakpoints, so that narrows it down to the loadselect function, however i cant narrow it down anymore, since no alerts will fire within the load select function. I dont have enough experience with JQuery to form an opinion on whats wrong. So im asking if anyone has had any success on what im trying to do, or if you can see something wrong with the code. And before anyone asks, yes i have checked the brackets.</p> <p><em>edit</em> Forgot to mention that i checked the error console for firefox and i get the error:</p> <pre><code>$(ddl).loadSelect is not a function. </code></pre> <p><em>edit</em> Found a resource that mentions that the error i described arises when you have two conflicting frameworks. So i put in jQuery.noConflict(); and it still does not work.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    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