Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Your reasoning so far is totally sound. First you are going to want to include the jquery library in your View / Master. You can download a copy of jquery from <a href="http://jquery.com/" rel="nofollow">http://jquery.com/</a>. Add the file to you project and include a <code>&lt;script src="/path/to/jquery.js"></code> to the <code>&lt;head></code> of your document. You are going to want to add another dropdown to your View (and probably another property to your model). We'll call this 'SelectedCategoryId:'</p> <pre><code>&lt;%=Html.DropDownList("SelectedCategoryId", null, "Select One...", new { style = "display:none;"}) %&gt; </code></pre> <p>We've set the style of this Drop Down to not be visible initially because there is nothing to select inside of it. We'll show it later after we generate some content for it. Now, somewhere on your page you will want to include a <code>&lt;script></code> block that will look something like this:</p> <pre><code>$(document).ready(function() { $('#SelectedPayeeId').change(function() { $.ajax({ type: 'POST', url: urlToYourControllerAction, data: { payeeId: $(this).val() }, success: function(data) { var markup = ''; for (var x = 0; x &lt; data.length; x++ ) { markup += '&lt;option value="' + data[x].Value + '"&gt;'+data[x].Text+'&lt;/option&gt;'; } $('#SelectedCategoryId').html(markup).show(); } }); }); }); </code></pre> <p>This code binds the anonymous function written above to the DOM element with the ID of 'SelectedPayeeId' (in this case your dropdown). The function performs an AJAX call to the url of your method. When it receives the results of the request (your JSON you returned) we iterate over the array and build a string of the html we want to inject into our document. Finally we insert the html into the 'SelectedCategoryId' element, and change the style of the element so it is visible to the user.</p> <p>Note that I haven't run this code, but it should be (almost) what you need. jQuery's documentation is available at <a href="http://docs.jquery.com/Main_Page" rel="nofollow">http://docs.jquery.com/Main_Page</a> and the functions I used above are referenced here:</p> <ul> <li><a href="http://api.jquery.com/ready/" rel="nofollow">.ready()</a></li> <li><a href="http://api.jquery.com/change/" rel="nofollow">.change()</a></li> <li><a href="http://api.jquery.com/jQuery.ajax/" rel="nofollow">jQuery.ajax()</a></li> <li><a href="http://api.jquery.com/html/" rel="nofollow">.html()</a></li> <li><a href="http://api.jquery.com/show/" rel="nofollow">.show()</a></li> </ul>
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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