I have two dropdownlist select2 based on another. But second drownlist do not working properly in MVC4.
@Html.DropDownList("company11", ViewData["companyy"] as List<SelectListItem>,"Select",new { @class = "validate[required]" })
@Html.DropDownList("brand11", ViewData["brandss"] as List<SelectListItem>,"Select",new { @class = "validate[required]" })
This jquery code:
$("#company11").change(function () {
checkUserIdentity();
var id = $(this).val();
binddropdownn_branch(id);
});
function binddropdownn_branch(id) {
$.ajax({
type: "POST",
url: '/Product/GetbarnchList?id=' + id,
data: {},
contentType: "application/json; charset=utf-8",
dataType: "json",
async: false,
success: function (result) {
$("#brand11").find('option').remove();
$.each(result, function () {
var option = $("<option/>");
option.attr("value", this.Value).text(this.Text);
$('#brand11').append(option);
});
}
});
}
Kindly reply me.

Vinay SinghPosted Jun 17, 2016, 2:21 AM
jQuery Ajax Cascaded DropdownList in Asp.net MVC Using C#.Net
Abhilash J APosted Jun 17, 2016, 3:39 AM
$("#brand11").find('option').remove();
$.each(result, function () {
$("#brand11").val(null).trigger("change");
var option = $("");
option.attr("value", this.Value).text(this.Text);
$('#brand11').append(option);
});
}