Note that there are some explanatory texts on larger screens.

plurals
  1. POCascading dropdown using asp.net mvc
    primarykey
    data
    text
    <p>I have a dropdown for tradertype which on selection should populate the dropdown for traders. My view looks like : </p> <pre><code>`&lt;ul&gt; &lt;li&gt; &lt;label&gt; &lt;span class="mandatory"&gt;*&lt;/span&gt;Trader Type:&lt;/label&gt; &lt;%=Html.DropDownList("TraderType", (SelectList)ViewData["TraderType"])%&gt; &lt;%--&lt;select id="ddlTraderType" name="TraderType"&gt; &lt;%foreach (SelectListItem item in (SelectList)ViewData["TraderType"]) { %&gt; &lt;option value="&lt;%=item.Value %&gt;"&gt; &lt;%=item.Text %&gt;&lt;/option&gt; &lt;%} %&gt; &lt;/select&gt;--%&gt; &lt;span class="tagline"&gt;Select a Trader type from here&lt;strong&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/li&gt; &lt;li&gt; &lt;label&gt; &lt;span class="mandatory"&gt;*&lt;/span&gt;Trader:&lt;/label&gt; &lt;select name="Trader" id="Trader"&gt; &lt;/select&gt; &lt;span class="tagline"&gt;Select a Trader from here&lt;strong&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/li&gt; &lt;/ul&gt;` </code></pre> <p>I tried using JQuery, but I couldn't get the change event of the 'TraderType' dropdown. My script is: </p> <pre><code>$("TraderType").change(function() { alert("Change"); $.ajax({ url: $("#ListTraders").attr("action"), type: 'GET', contentType: "application/json; charset=utf-8", cache: false, data: { part: $("#TraderType").val() }, dataType: 'json', async: false, success: function(data) { if ((data.lstTraders.length) &gt; 0) { for (var count = 0; count &lt; data.lstTraders.length; count++) { $("#Trader").append("&lt;option value='" + data.lstTraders[count].Id.toString() + "'&gt;" + data.lstTraders[count].TraderName + "&lt;/option&gt;"); } } } }); }); </code></pre> <p>The code in the controller is: </p> <pre><code>public JsonResult ListTraders(string trdrTypeId) { IList&lt;HSTrader&gt; lstTraders = new List&lt;HSTrader&gt;(); Build objBld = new Build(); Document objDoc = new Document(); string message = string.Empty; bool result = true; try { int trdrType = Convert.ToInt32(trdrTypeId); lstTraders = objBld.GetTradersByTrdrTypeId(trdrType); } catch (Exception ex) { message = ex.Message; result = false; } return Json(new { Success = result, Message = message, lstTraders = lstTraders });} </code></pre> <p>Please help me on this. </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.
 

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