I am trying to follow the examples to cascade two dropdown lists. It seems the databind is not working. I am population the dropdowns from ViewBag. When I debug, I see it get all the way through the databind, no errors, but the second dropdown just says "No Records Found". I don't understand how it can send the query and repoplulate the ViewBag variable. Here is the code I am using:
First Dropdown:
<div class="form-group">
@Html.LabelFor(model => model.AID, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EJS().DropDownList("AID").Placeholder("Select an Agency").PopupHeight("200px").Change("aidchange").DataSource((IEnumerable<Object>)ViewBag.AgencyDD).Fields(df => df.Text("Agency").Value("ID")).Width("150px").Value(Model.AID).Render()
@Html.ValidationMessageFor(model => model.AID, "", new { @class = "text-danger" })
</div>
</div>
Second Dropdown:
<div class="form-group">
@Html.LabelFor(model => model.agency_contact, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EJS().DropDownList("agency_contact").Placeholder("Select an Agency Contact").PopupHeight("200px").DataSource((IEnumerable<Object>)ViewBag.AgencyContactDD).Fields(df => df.Text("AgeConName").Value("ID")).Width("150px").Value(Model.agency_contact).Render()
@Html.ValidationMessageFor(model => model.agency_contact, "", new { @class = "text-danger" })
</div>
</div>
javascript:
function aidchange() {
var agency_contact = document.getElementById('agency_contact').ej2_instances[0];
var AID = document.getElementById('AID').ej2_instances[0];
agency_contact.enabled = true;
var tempQuery = new ej.data.Query().where('AID', 'equal', AID.value);
agency_contact.query = tempQuery;
agency_contact.text = null;
agency_contact.dataBind();
}