Encontre una buena solución, en el Controller:
Public Function Index() As ActionResult
ViewData("titulo") = "cascada de prueba"
Using db As New BD_LOSCOPIHUESEntities1
Dim regiones = db.REGION.Select(Function(x) New With { _
.Value = x.IdRegion, _
.Text = x.Nombre}).ToList()
Dim model As New DropDownListCascadeViewModel()
model.regiones = New SelectList(regiones, "Value", "Text")
model.ciudades = New SelectList(New List(Of SelectListItem)(), "Value", "Text")
Return View(model)
End Using
End Function
<HttpPost> _
Public Function GetCiudades(typeCiudad As String) As JsonResult
Dim type As Integer = Integer.Parse(typeCiudad)
Dim list As New List(Of SelectListItem)()
Using db As New BD_LOSCOPIHUESEntities1
Dim ciudadesSelect = db.CIUDAD.Where(Function(y) y.IdRegion = type).Select(Function(x) New With { _
.Value = x.IdCiudad, _
.Text = x.Nombre}).ToList()
Dim model As New DropDownListCascadeViewModel()
model.ciudades = New SelectList(ciudadesSelect, "Value", "Text")
Return Json(New With {model.ciudades})
End Using
End Function
Creé una clase de tipo ViewModel(es la forma que le llamo):
Public Class DropDownListCascadeViewModel
Public Property selectedRegion() As Integer
Get
Return m_selectedRegion
End Get
Set(value As Integer)
m_selectedRegion = value
End Set
End Property
Private m_selectedRegion As Integer
Public Property selectedCiudades() As Integer
Get
Return m_selectedCiudades
End Get
Set(value As Integer)
m_selectedCiudades = value
End Set
End Property
Private m_selectedCiudades As Integer
Public regiones As System.Web.Mvc.SelectList
Public ciudades As System.Web.Mvc.SelectList
End Class
y en la vista, al principio referencia al ViewModel que hice:
<%@ Page Language="VB" Inherits="System.Web.Mvc.ViewPage(Of IMPCHLosCopihues_MVC.DropDownListCascadeViewModel)" %>
A traves de Jquery con AJAX en la Vista:
<script type="text/javascript" src="../../Scripts/jquery-1.11.3.min.js"> </script>
<script type="text/javascript">
$(function () {
$('#selectedRegion').change(function () {
var typeCiudad = $('#selectedRegion :selected').val();
typeCiudad = typeCiudad == "" ? 0 : typeCiudad;
//When select 'optionLabel' we need to reset it to default as well. So not need
//travel back to server.
if (typeCiudad == "") {
$('#selectedCiudades').empty();
$('#selectedCiudades').append('<option value="">--Select a language--</option>');
return;
}
//This is where the dropdownlist cascading main function
$.ajax({
type: "POST",
url: "GetCiudades", //Your Action name in the DropDownListConstroller.cs
data: "{'typeCiudad':" + typeCiudad + "}", //Parameter in this function, Is cast sensitive and also type must be string
contentType: "application/json; charset=utf-8",
dataType: "json"
}).done(function (data) {
//When succeeded get data from server construct the dropdownlist here.
if (data != null) {
$('#selectedCiudades').empty();
$.each(data.ciudades, function (index, data) {
$('#selectedCiudades').append('<option value="' + data.Value + '">' + data.Text + '</option>');
});
}
}).fail(function (response) {
if (response.status != 0) {
alert(response.status + " " + response.statusText);
}
});
});
});
<body>
Region<%: Html.DropDownListFor(Function(m) m.selectedRegion, Model.regiones, "--Seleccione la Region--")%>
<br />
Ciudad <%:Html.DropDownListFor(Function(m) m.selectedCiudades, Model.ciudades, "--Seleccione la Ciudad--")%>
<br />
</body>
Y así puedo tener Dropdownlist dependientes.
¿El asunto es como cargar los datos guardados en los Dropdownlist, para hacer los Update?