Here's the definition of the two items that are linked by the CascadeFrom:
items.Add().Field(f => f.Country)
.ColSpan(1)
.Name("cmbCountry")
.Editor(e => e.ComboBox()
.AutoWidth(false)
.DataTextField("name")
.DataValueField("id")
.BindTo(@CountryModel.Countries)
.Placeholder("--- Select or Type Country"));
items.Add().Field(f => f.StateProvince)
.ColSpan(1)
.Name("cmbStatesProvinces")
.Editor(e => e.ComboBox()
.AutoWidth(false)
.AutoBind(false)
.Placeholder("--- Select State/Province ---")
.DataTextField("name")
.DataValueField("id")
.DataSource(dS => dS.Read(read => read.Action("GetStateList", "Address").Data("filterState")).ServerFiltering(true))
.CascadeFrom("cmbCountry")
@*.BindTo(@StatesProvinces.StateProvince)*@
);
Here's the AddressController.GetStateList:
{
JsonResult? retval = null;
if (!string.IsNullOrEmpty(Country))
{ var Country_ID = CountryModel.Countries.Where(s => s.name == Country).ToList()[0].code;
var State = StatesProvinces.StateProvince.Where(s => s.countryCode == Country_ID);
retval = Json(State.Select(s => new { id = s.id, name = s.name }).ToList());
}
else
retval = Json(StatesProvinces.StateProvince);
return retval;
}
This works for the first Country that is selected... afterwards - if the Country is changed, the GetStateList is not called again to refresh the related/CascadeFrom Combobox.