Note that there are some explanatory texts on larger screens.

plurals
  1. POCascading DropDown not return value
    primarykey
    data
    text
    <p>I have a two cascading dropdown, when I run the application everything works fine, because the cascade works, but when I get the value of the dropdown only get the value of first dropdown. The second I always get the value of zero.</p> <p>The ViewModel code:</p> <pre><code>public class MyViewModel { public string SelectedUniversidadId { get; set; } public string SelectedCiudadId { get; set; } public IEnumerable&lt;UNIVERSIDAD&gt; Universidades { get; set; } } </code></pre> <p>Partial view code:</p> <pre><code>&lt;script type="text/javascript"&gt; $(function () { $('#universidad').change(function () { var selectedUniversidadId = $(this).val(); $.getJSON('@Url.Action("GetCiudadList", "Consultorio", new { Area = "Superusuario", controller = "Consultorio" })', { UniversidadId: selectedUniversidadId }, function (myData) { var citiesSelect = $('#ciudad'); citiesSelect.empty(); $.each(myData, function (index, itemData) { citiesSelect.append($('&lt;option/&gt;', { value: itemData.Value, text: itemData.Text })); }); }); }); }); &lt;/script&gt; @model RolesMVC3.Areas.Superusuario.Models.MyViewModel &lt;div&gt; Universidad: @Html.DropDownListFor(x =&gt; x.SelectedUniversidadId, new SelectList(ViewBag.IdUniversidad, "IdUniversidad", "Nombre"), "-- Selecione Universidad --", new { id = "universidad" }) &lt;/div&gt; &lt;div&gt; Ciudad: @Html.DropDownListFor(x =&gt; x.SelectedCiudadId, Enumerable.Empty&lt;SelectListItem&gt;(), "-- Seleccione Ciudad --", new { id = "ciudad" }) &lt;/div&gt; </code></pre> <p>Controller code:</p> <pre><code> public ActionResult GetCiudadList(int UniversidadId) { decimal idd = (decimal)UniversidadId; var universidades = (from u in db.UNIVERSIDAD join s in db.SEDE_UNIVERSIDAD on u.IdUniversidad equals s.IdUniversidad join c in db.CIUDAD on s.IdCiudadSede equals c.IdCiudad where u.IdUniversidad == idd select c).ToList(); var myData = universidades.Select(a =&gt; new { Text = a.NombreCiudad, Value = a.IdCiudad.ToString(), }); return Json(myData, JsonRequestBehavior.AllowGet); </code></pre> <p>Thanks and blessings</p>
    singulars
    1. This table or related slice is empty.
    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.
    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