Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>How about either (1) using JQuery and loading the drop-down with a Partial view returned by your controller or (2) you could have an AJAX call that would return your values as a JSON object mapped from your entity and you can render them in the drop-down. This way your form won't be submitted every time you update a drop-down.</p> <p>The first solution might look something like this:</p> <p><strong>JQUERY</strong></p> <pre><code>&lt;script&gt; $("#searchContinent").change(function() { $("#searchCountry").load("/YourController/GetCountries", { 'continentId': $(this).val() }, function (response, status, xhr) { if (status == "error") { alert("An error occurred while loading the results."); } }); }); &lt;/script&gt; @Html.DropDownList("searchContinent", null, "-- All continents --" }) &lt;div id="searchCountry"&gt; &lt;!--the newly created drop-down will be placed here--&gt; &lt;/div&gt; </code></pre> <hr> <p><strong>(EDIT)</strong></p> <p>For Javascript you might try something like this:</p> <p><strong>YOUR CURRENT VIEW</strong></p> <pre><code>@Html.DropDownList("searchContinent", null, "-- All continents --", new { onchange = "getCountries(this)" }) &lt;div id="searchCountry"&gt; &lt;!--the newly created drop-down will be placed here--&gt; &lt;/div&gt; &lt;script&gt; function getCountries(input){ var selectedValue = input.options[input.selectedIndex].value; var xhReq = new XMLHttpRequest(); xhReq.open("GET", "YourController/GetCountries?continentId="+selectedValue, false); xhReq.send(null); var serverResponse = xhReq.responseText; document.getElementById("searchCountry").innerHTML=serverResponse ; } &lt;/script&gt; </code></pre> <p><strong>DISCLAIMER:</strong> This I have never tried so if it's wrong don't hesitate to let me know and correct it if necessary</p> <p><strong>(END EDIT)</strong></p> <hr> <p><strong>CONTROLLER</strong></p> <pre><code>public ActionResult GetCountries(string continentId) { /*Get your countries with your continentId and return a Partial View with a list of countries as your model*/ return PartialView(countryList); } </code></pre> <p><strong>GetCountries VIEW</strong></p> <pre><code>@model IEnumerable&lt;SchoolCup.Domain.Country&gt; @Html.DropDownListFor( 0, Model) </code></pre>
    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.
 

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