I want to achieve that parent list dropdown list gets to its initial state, say (--Select Category--) the the child dropdown should also unload and get disabled and show --Select Subcategory> until user selects the Category from parent table. Current output is
but I want to achieve 
View
<div class="form-group">
@Html.LabelFor(model => model.facultyId, "Faculty", htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.DropDownList("facultyId", new SelectList(ViewBag.facultyList, "facultyId", "facultyName"), "--Select Faculty--", htmlAttributes: new { @class = "form-control" })
@Html.ValidationMessageFor(model => model.facultyId, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.departmentId, "departmentId", htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.DropDownList("departmentId", new SelectList(""), "--Select Department--", htmlAttributes: new { @class = "form-control" })
@Html.ValidationMessageFor(model => model.departmentId, "", new { @class = "text-danger" })
</div>
</div>
//jQuery Function
<script src="~/Scripts/jquery-3.4.1.js"></script>
<script src="~/Scripts/jquery-3.4.1.min.js"></script>
<script>
$(document).ready(function () {
$("#facultyId").change(function () {
$.get("/StudentCtrl/GetDeptName", { facultyId: $("#facultyId").val() }, function (data) {
$("#departmentId").empty(); //to remove old loaded items
$.each(data, function (key, val) {
$("#departmentId").append("<option value='" + val.departmentId + "'>" + val.departmentName + "</option>");
});
});
})
})
</script>
Controller
studentDBEntities db = new studentDBEntities();
public ActionResult Create()
{
var facList = db.tbl_faculty.ToList();
ViewBag.facultyList = facList;
return View();
}
public JsonResult GetDeptName(int facultyId)
{
db.Configuration.ProxyCreationEnabled = false;
List<tbl_Department> dep = db.tbl_Department.Where(x=>x.facultyId== facultyId).ToList();
return Json(dep, JsonRequestBehavior.AllowGet);
}
